akhauriyash/Code-Regression huggingface dataset:
while True:
    try:
        p,q = [int(x) for x in input().split()]
    except:
        break

    L = []
    s = ""
    p %= q
    f = None
    L.append(p)
    i = 0
    if p == 0:
        #print(0)
        continue
    
    while p > 0:
        i = i+1
        p *=10
        r = p // q
        p %=q
        s += str(r)
        if p in L:
            f = L.index(p)
            break
        else:
            L.append(p)
    print(s)
    if f is not None:
        t = " " * f + "^" * (len(s)-f)
        print(t)



Measured memory_bytes: 5604
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
#define MOD 1000000007
int main()
{   
    int n;
    ll a[200005] = {}, c[200005] = {}, z = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i], c[a[i]]++;
    for (int i = 1; i <= n; i++) z += c[i] * (c[i] - 1) / 2;
    for (int i = 1; i <= n; i++) cout << z - c[a[i]] + 1 << '\n';
    return 0;
}

Measured memory_bytes: 6740
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        int N = sc.nextInt();
        int x = sc.nextInt();
        var a = sc.ArrayLong(N);

        long ans = 0;
        long sum = a[0] + a[1];
        if (sum > x) {
            ans += sum - x;
            a[1] = Math.Max(a[1] - sum, 0);
        }

        var A = new long[N - 1];
        for (int i = 1; i < N; i++) {
            A[i - 1] = a[i - 1] + a[i];
        }

        for (int i = 1; i < A.Length; i++) {
            if (A[i] > x) {
                var minus = A[i] - x;
                ans += minus;
                A[i] -= minus;
                if (i != A.Length -1) {
                    A[i + 1] -= minus;
                }
            }
        }
        WriteLine(ans);
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {


        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}

Measured memory_bytes: 28252
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int cnt = 0;
	for(int i=1; i<=n; i++){
		int k = 0;
		int num = i;
		while(num){
			num /= 10;
			k++;
		}
		if(k%2){
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> al = new ArrayList<>();
		boolean b;
		int cnt = 0;
		for (int i = 11; i <= 55555; i = i + 2) {
			b = true;
			for (int j = 2; j * j <= i; j++) {
				if (i % j == 0) {
					b = false;
					break;
				}
			}
			if (b && i % 5 == 1) {
				al.add(i);
				cnt++;
				if (cnt == n) {
					break;
				}
			}
		}
		for (int i : al) {
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int d[100005];
int main()
{
	 int n;
	 cin>>n;
	 for(int i=1;i<=n;i++)
	 {
	 	cin>>d[i];
	 }
	 sort(d+1,d+1+n);
	 double maxn=d[1];
	 for(int j=1;j<n;j++)
	 {
	 	maxn=(maxn+d[j+1])/2;
	 }
	 cout<<maxn;
	 return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	int N;
	cin >> N;
	vector<lint>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	int M;
	cin >> M;
	lint tmp = 0;
	set<lint>S;
	rep(i, M) {
		cin >> tmp;
		S.insert(tmp);
	}
	rep(i, N) {
		if (!S.count(A[i])) {
			cout << A[i] << endl;
		}
	}
}




Measured memory_bytes: 13596
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll n, m;
    cin >> n >> m;
    if(abs(n - m) > 1){
        cout << 0 << endl;
        return 0;
    }else{
        ll ans = 1;
        ll mod = 1000000007;
        for(int i = 2; i <= min(n, m); i++){
            ans *= i;
            ans %= mod;
            ans *= i;
            ans %= mod;
        }
        if(n == m){
            ans *= 2;
            ans %= mod;
            cout << ans << endl;
        }else{
            ans *= max(n, m);
            ans %= mod;
            cout << ans << endl;
        }
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
char a[610][610];
int H, W, d;
bool isin(int i, int j){
  if( 0 <= i && i < 610 &&
      0 <= j && j < 610 )
    return true;
  return false;
}
void f(int h, int w, char c){
  int dd = (d-1) / 2;
  for(int k = -dd; k <= dd; k++){
    for(int i = h + abs(k); i <= h + d - 1 - abs(k); i++){
      if( isin(i, w+k) )
	a[i][w+k] = c;
    }
  }
}
void f2(int h, int w, char c){
  int dd = d / 2;
  for(int dh = 0; dh < dd; dh++){
    for(int ww = w + dh; ww <= w + d - 2 - dh; ww++){
      if( isin( h + dh, ww ) ){
	a[h + dh][ ww ] = c;
      }
      if( isin( h - 1 - dh, ww ) ){
	a[h - 1 - dh][ ww ] = c;
      }
    }
  }
}

int main(){
  cin >> H >> W >> d;
  for(int i = 0; i <= 610 + d; i += d){
    for(int j = 0; j <= 610 + d; j += d){
      if( (i/d + j/d) % 2 == 0 ){
	f( i, j, 'R');
      }else{
	f( i, j, 'G');
      }
    }
  }
    for(int i = 0; i <= 610 + d; i += d){
      for(int j = 1; j <= 610 + d; j += d){
	if( (i/d + (j-1)/d) % 2 == 0 ){
	  f2( i, j, 'B');
	}else{
	  f2( i, j, 'Y');
	}
      }
    }
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if( a[i][j] == 0 )
	cout << ".";
      else
	cout << a[i][j];
    }
    cout << endl;
  }
}


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

typedef unsigned long long ll;
#define mod 1000000007
#define all(x) (x).begin(),(x).end()


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll t;
  cin>>t;
  ll a=0,w=0,tl=0,re=0;
  vector<string> str(t);
  for(string &s:str){
    cin>>s;
    if(s=="AC")
      ++a;
    else if(s=="WA")
      ++w;
    else if(s=="TLE")
      ++tl;
    else
      ++re;
  } 
  cout<<"AC x "<<a<<"\n"
        <<"WA x "<<w<<"\n"
        <<"TLE x "<<tl<<"\n"
        <<"RE x "<<re<<"\n";
  
  return 0;
}

Measured memory_bytes: 6316
#include <bits/stdc++.h>
using namespace std;
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }



int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> adj(n);
	for(int i = 0; i < m; ++ i){
		int u, v;
		cin >> u >> v, -- u, -- v;
		adj[u].push_back(v), adj[v].push_back(u);
	}
	vector<int> vis(n);
	int res = 0;
	for(auto u = 0; u < n; ++ u){
		if(!vis[u]){
			int cur = 0;
			function<void(int)> dfs = [&](int u){
				++ cur;
				vis[u] = true;
				for(auto v: adj[u]){
					if(!vis[v]){
						dfs(v);
					}
				}
			};
			dfs(u);
			ctmax(res, cur);
		}
	}
	cout << res << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

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

signed main(){
  int A,B,C;
  cin >> A >> B >> C;
  C-(A-B)>0 ? cout << C-(A-B) << endl : cout << "0" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define PI pair<int,int>
#define TP pair<int,PI>
#define ff first
#define ss second
#define MOD 1000000007


int32_t main()
{
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif*/

	string s;
	cin>>s;
	int n=s.size()+1;
	int a[n]={0};
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='<')
			a[i+1]=a[i]+1;
	}

	for(int i=n-2;i>=0;i--)
	{
		if(s[i]=='>')
		{
			a[i]=max(a[i],a[i+1]+1);
		}
	}

	int ans=0;
	for(int i=0;i<n;i++){
		//cout<<a[i]<<" ";
		ans+=a[i];
	}
	cout<<ans<<endl;

}



Measured memory_bytes: 4740
N = input().split()

N[0] = int(N[0])
N[1] = int(N[1])
N[2] = int(N[2])

if(N[0] == 1):
    if(N[1] == N[2]):
        print("1")
        exit()
    print("0")
    exit()

if(N[1] > N[2]):
    print("0")
    exit()

print((N[2] * (N[0] -1) + N[1]) - (N[1] * (N[0] - 1) + N[2]) + 1)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int k,n,fl; long long p,w;
long long X(int n){
	long long s=1,x=p*(k-1);
	for (int i=0;i<=n;++i){
		s*=k; if (!fl&&s-1>x) return p+1;
	}
	return (s-1)/(k-1);
}
int main(){
	scanf("%d%d",&k,&n);
	if (k==1){
		for (int i=1;i<=(n+1)/2;++i) printf("1 "); puts(""); return 0;
	}
	if (k&1){
		for (int i=1;i<=n;++i){
			w=X(n-i);
			if (!fl&&p<w) printf("%d ",k+1>>1),++p;
			else{
				fl=1;
				if (p>=0){
					int j=w*k+p+1>>1;
					if (j<=p) {puts(""); return 0;}
					j=(j-p-1)/w+1;
					printf("%d ",j);
					p+=(j+j-k-1)*w+1;
				}else{
					int j=w*k-p+1>>1;
					if (j>w*k) {puts(""); return 0;}
					j=(j-1)/w+1;
					printf("%d ",j);
					p+=(j+j-k-1)*w+1;
				}
			}
		}
	}else{
		printf("%d ",k/2);
		for (int i=1;i<n;++i) printf("%d ",k);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int r,c,k,b;
string maze[200];
bool test(int row[],int col[])
{
    int cnt=b;
    for(int i=0; i<r; i++)
    {
        for(int j=0; j<c; j++)
        {
            if((row[i] && maze[i][j]=='#')|| (col[j] && maze[i][j]=='#'))
                cnt--;
        }
    }
    if(cnt==k)
        return 1;
    else
        return 0;
}
int ans,cnt;
void COLM(int R[],int C[],int pos)
{
    ans+=test(R,C);
    cnt++;
    for(int i=pos; i<c; i++)
    {
        C[i]=1;
        COLM(R,C,i+1);
        C[i]=0;
    }
}
void ROW(int R[],int C[],int pos)
{
    ans+=test(R,C);
    for(int i=pos; i<r; i++)
    {
        R[i]=1;
        ROW(R,C,i+1);
        COLM(R,C,0);
        R[i]=0;
    }
}
void SUB(int R[],int C[],int pos)
{
    ans-=test(R,C);
    for(int i=pos; i<r; i++)
    {
        R[i]=1;
        SUB(R,C,i+1);
        R[i]=0;
    }
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>r>>c>>k;
    for(int i=0; i<r; i++)
    {
        cin>>maze[i];
    }
    for(int i=0; i<r; i++)
    {
        for(int j=0; j<c; j++)
            if(maze[i][j]=='#')
                b++;
    }
    int R[10]= {0},C[10]= {0},X[10]= {0},Y[10]= {0};
    ROW(R,C,0);
    COLM(X,Y,0);
    SUB(R,C,0);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
   int n,m;
   int k[30];
   int a[30][30];
   int ans = 0;
   int count[30]={0};
   cin >> n >> m;
   for(int i = 0; i < n; i++){
       cin >> k[i];
       for(int j = 0; j <k[i] ; j++){
           cin >> a[i][j];
       }
   }
   rep(i,n){
       rep(j,k[i]){
          count[a[i][j]-1]++;

       }
   }
   rep(i,m){
       if(count[i]==n) ans++;
   }
  cout << ans << endl;

    return 0;
}


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

using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
	int N, M;
	cin >> N;
	map<string, int> s;
	for (int i = 0; i < N; ++i) {
		string str;
		cin >> str;
		s[str]++;
	}
	cin >> M;
	for (int i = 0; i < M; ++i) {
		string str;
		cin >> str;
		s[str]--;
	}

	int ans = 0;
	for (auto i : s) {
		ans = max(ans, i.second);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n; cin >> n;
  vector<int> a(n+2);
  for(int i=0;i<n;i++) cin >> a[1+i];
  int sum = 0;  
  for(int i=0;i<=n;i++) sum += abs(a[i] - a[i+1]);
  for(int i=0;i<n;i++) cout <<
    sum - abs(a[i] - a[i+1]) - abs(a[i+1] - a[i+2]) + abs(a[i] - a[i+2])
    << endl;
  return 0;
}

Measured memory_bytes: 1664
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class ABC_108_B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int x1 = in.nextInt();
            int y1 = in.nextInt();
            int x2 = in.nextInt();
            int y2 = in.nextInt();

            int x3, x4, y3, y4;
            int distX = x2 - x1;
            int distY = y2 - y1;

            x3 = x2 - distY;
            y3 = y2 + distX;
            x4 = x3 - distX;
            y4 = y3 - distY;

            out.print(x3 + " " + y3 + " " + x4 + " " + y4);


        }

    }
}



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

int main() {
    string s;
    cin >> s;
    ll ans = 0;
    int n = s.size();
    int i = 0;
    int aseq = 0;
    while(i < n - 2){
        if(s[i] == 'A'){
            aseq++;
            if(s[i+1] == 'B' && s[i+2] == 'C'){
                ans += aseq;
                i += 2;
                s[i] = 'A';
                aseq--;
            }else{
                i++;
            }
        }else{
            aseq = 0;
            i++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] a = new int[n];
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        for(int i = 0; i < n; i++) a[i] = Integer.parseInt(line1[i]);
        int[] b = new int[n];
        String line2 = sc.nextLine();
        String[] line3 = line2.split(" ");
        for(int i = 0; i < n; i++) b[i] = Integer.parseInt(line3[i]);
        int[] c = new int[n - 1];
        String line4 = sc.nextLine();
        String[] line5 = line4.split(" ");
        for(int i = 0; i < n - 1; i++) c[i] = Integer.parseInt(line5[i]);

        int count = 0;
        for(int i = 0; i < n; i++) count += b[i];
        
        for(int i = 0; i < n - 1; i++){
            if(a[i] + 1 == a[i + 1])    count += c[a[i] - 1];
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23764
#define _USE_MATH_DEFINES  // M_PI等のフラグ

#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <list>

#define MOD 1000000007
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

string replace_with_str(string str, string str_from, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(str_from, pos), pos != string::npos) {
        str.replace(pos, str_from.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

void solve(){
    char c;
    cin >> c;
    if (65 <= c && c <= 90) {
        cout << "A\n";
    }
    else {
        cout << "a\n";
    }
}

int main(int argc, char const *argv[]){
    solve();
    return 0;
}

Measured memory_bytes: 3564
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
*/
//入力終了→Ctrl+D
import java.util.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        long n=sc.nextLong();
        long x=sc.nextLong();
        out.println(f(x,n-x)+n);
    }
    static long f(long a,long b){
        if(a>b){
            long t=a;
            a=b;
            b=t;
        }
        if(b%a==0) return (b/a-1)*2*a+a;
        return 2*a*(b/a)+f(b%a,a);
    }
}

Measured memory_bytes: 21716
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
a3 = list(map(int,input().split()))
t1 = [0,0,0]
t2 = [0,0,0]
t3 = [0,0,0]
n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(3):
        if a1[i]==b: t1[i]=1
        if a2[i]==b: t2[i]=1
        if a3[i]==b: t3[i]=1

l=[1,1,1]
if t1==l or t2==l or t3==l:
    print('Yes')
    exit(0)
if [t1[0],t2[0],t3[0]]==l or [t1[1],t2[1],t3[1]]==l or [t1[2],t2[2],t3[2]]==l:
    print('Yes')
    exit(0)
if [t1[0],t2[1],t3[2]]==l or [t1[2],t2[1],t3[0]]==l:
    print('Yes')
    exit(0)
print('No')

Measured memory_bytes: 3064
// Best practice
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 
 
#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 
 
#define fbo find_by_order
#define ook order_of_key
 
 vector<bool> sv(100005,true);
 
signed main() {
   tezz
   
    sv[0]=sv[1]=false;
    for(int i=2; i<100005; i++){
        if(sv[i])    {
            for(int j=i*i; j<=100005; j+=i){
                sv[j]=false;
            }
        }
    }
    int n;
    cin >> n;
    while(sv[n]==false){
        n++;
    }
    cout << n << endl;
   
   return 0;
}
 


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

int main(void) {
  string S, T;
  cin >> S >> T;

  for (int i = 0; i < S.size(); ++i) {
    if (S == T) {
      cout << "Yes" << endl;
      return 0;
    }

    string temp = "";
    temp.append(1, S[S.size() - 1]);
    temp += S.substr(0, S.size() -1);
    S = temp;
  }

  cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
inline int Abs(int x){return x<0?-x:x;}
inline int gcd(int a,int b)
{
	while(a&&b) if(a>b) a%=b;else b%=a;
	return a?a:b;
}
int a[10010],n,v=0,isprime[10010],val[10010];
set<int> ans;
inline int check(int x)
{
	for(int i=0;i<x-1;i++) val[i]=0;
	for(int i=0;i<=n;i++) val[i%(x-1)]=(val[i%(x-1)]+a[i]%x+x)%x;
	for(int i=0;i<x-1;i++) if(val[i]) return 0;
	return 1;
}
int main()
{
	scanf("%d",&n);
	for(int i=n;i>=0;i--) scanf("%d",a+i),v=gcd(v,Abs(a[i]));
	for(int i=2;i*i<=v;i++) if(v%i==0)
		{while(v%i==0) v/=i;ans.insert(i);}
	if(v>1) ans.insert(v);
	for(int i=2;i<=n;i++) isprime[i]=1;
	for(int i=2;i<=n;i++) if(isprime[i]) for(int j=i+i;j<=n;j+=i) isprime[j]=0;
	for(int i=2;i<=n;i++) if(isprime[i]&&a[0]%i==0&&check(i)) ans.insert(i);
	for(set<int>::iterator it=ans.begin();it!=ans.end();it++) printf("%d\n",*it);
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

// 600, 27min

string S, T;
int q;
int A[MAX_N] = {};
int B[MAX_N] = {};
int C[MAX_N] = {};
int D[MAX_N] = {};

// 一次元累積和
template< typename T >
class CumulativeSum
{
public:
    vector< T > m_data;
    CumulativeSum() {};
    CumulativeSum(int sz) : m_data(sz, 0) {};

    // k に x を加える O(1)
    void Add(int k, int x) {
        assert(m_data.size() >= k);
        if(m_data.size() <= k) { m_data.push_back(x); }
        else { m_data[k] += x; }
    }

    // 累積和の構築 O(m_data.size())
    void Build() { for(int i = 1; i < m_data.size(); i++) { m_data[i] += m_data[i - 1]; } }

    // 区間 [0, k] の和を返す O(1)
    // 閉区間なので k が含まれることに注意
    T Query(int k) {
        if(k < 0) { return 0; }
        return (m_data[min(k, (int) m_data.size() - 1)]);
    }

    // 区間 [l, h] の和を返す O(1)
    // 閉区間なので k が含まれることに注意
    // 制約：l <= h
    T Query(int l, int h) { return this->Query(h) - this->Query(l-1); }
};

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

    CumulativeSum<int> cs_s(S.length() + 1);
    CumulativeSum<int> cs_t(T.length() + 1);

    REP(i, q) {
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        A[i]--;
        B[i]--;
        C[i]--;
        D[i]--;
    }
    REP(i, S.length()) {
        if(S[i] == 'A') { cs_s.Add(i, 1); }
        else { cs_s.Add(i, 2); }
    }
    REP(i, T.length()) {
        if(T[i] == 'A') { cs_t.Add(i, 1); }
        else { cs_t.Add(i, 2); }
    }
    cs_s.Build();
    cs_t.Build();
    REP(i, q) {
        if(abs(cs_s.Query(A[i], B[i]) - cs_t.Query(C[i], D[i])) % 3 == 0) { printf("YES\n"); }
        else { printf("NO\n"); }
    }

    return 0;
}


Measured memory_bytes: 3200
use std::cmp::max;
// from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn main() {
    input! {n: usize, aa: [i32; n]};
    let mut left = vec![0; n];
    let mut right = vec![0; n];

    let mut candidate = 0;
    for i in 0..n {
        candidate = max(candidate, aa[i]);
        left[i] = candidate
    }

    let mut candidate = 0;
    for i in 0..n {
        let index = n - (i + 1);
        candidate = max(candidate, aa[index]);
        right[index] = candidate
    }

    for i in 0..n {
        let left_max = if i > 0 { left[i - 1] } else { 0 };
        let right_max = if i < n - 1 { right[i + 1] } else { 0 };
        println!("{}", max(left_max, right_max))
    }
}


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

int parent_find( int x, vector<int>  &parent)
{
  while(parent[x]!=x)
  {
    x=parent[x];
  }
  return x;

}

void combine( int x,int y , vector<int> &parent, vector<int> &rank)
{
  int t=parent_find(x,parent);
  int w=parent_find(y,parent);
  if(t!=w)
  {

  if(rank[w]>rank[t])
   {  
  parent[t]=w;
  rank[w]+=rank[t];
   }
  else
   {
     parent[w]=t;
    rank[t]+=rank[w];
    
   }
  
  }
  
}

int main()
{
  int n;
  cin>>n;
  vector<int> group(n+1,0);
  vector<int> rank(n+1,1);
  for(int i=0;i<=n;i++)
     group[i]=i;
  
  int t;
  cin>>t;
  while(t--)
  {
    int x,y;
    cin>>x>>y;
    combine(x,y,group,rank);
  }

  cout<<*max_element(rank.begin(),rank.end())<<endl;
  




    return 0;
}

Measured memory_bytes: 4828
#dp[i][v] = min dp[i-1][v], dp[i-1][v-vi] + wi
N, W = [int(_n) for _n in input().split()]
weights = []
values = []
for i in range(N):
    w,v = [int(_n) for _n in input().split()]
    weights.append(w)
    values.append(v)
V = max(values) * N+1
INF = 10**12
dp = [[INF]*(V+1) for _ in range(N)]

for v in range(V+1):
    dp[0][v] = INF if v > values[0] else weights[0]
dp[0][0] = 0
for i in range(1,N):
    for v in range(V+1):
        dp[i][v] = min(dp[i-1][v], dp[i-1][max(0,v-values[i])] + weights[i])
ok = 0
ng = V
while ng - ok > 1:
    mid = (ng+ok)//2
    if dp[N-1][mid] > W:
        ng = mid
    else:
        ok = mid
print(ok)

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

int x[10],y[10];

double dist(int i, int j){
  double dx = x[i] - x[j];
  double dy = y[i] - y[j];
  return pow(dx*dx + dy*dy, 0.5);
}

int main() {
  int n;
  cin >>n;
  for(int i = 1; i<=n; i++) cin >>x[i] >>y[i];
  double sum = 0.0;
  vector<int> v(n);
  rep(i,n) v[i] = i+1;
  do {
    rep(i,n-1) sum += dist(v[i], v[i+1]);  
  } while(next_permutation(v.begin(), v.end()));
  int Factorial = 1;
  for(int i = 2; i<=n; i++) Factorial *= i;
  cout << fixed << setprecision(12) << sum/Factorial << endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	vector<int> a(100000);
	vector<int> b(100000,0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] != 0)b[a[i]-1]++;
		if (a[i] != 100000)b[a[i]+1]++;
		b[a[i]]++;
	}
	sort(b.rbegin(), b.rend());
	cout <<b[0]<< endl;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		HashMap<Integer,Integer> map=new HashMap<>();
		int tmp=0;
		int ten=1;
		for(int i=s.length()-1; i>=0; i--){
			tmp=(tmp+(s.charAt(i)-'0')*ten)%2019;
			if(map.containsKey(tmp)){
				map.put(tmp,map.get(tmp)+1);
			}else{
				map.put(tmp,1);
			}
			ten=ten*10%2019;
		}
		long ans=0;
		for(int i=1; i<2019; i++){
			if(map.get(i)!=null){
				ans+=(long)(map.get(i)*(map.get(i)-1)/2);
			}
		}
		if(map.get(0)!=null){
			ans+=map.get(0);
			ans+=map.get(0)*(map.get(0)-1)/2;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 51788
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

ll dp[6010][12010];

int main() {
    ll N, M; scanf("%lld%lld", &N, &M);
    
    int ofs = 6000;
    dp[0][ofs] = 1;
    for(int i=0; i<3*N; i++) {
        for(int j=0; j<=2*ofs; j++) {
            if(dp[i][j] == 0) continue;
            if(i+1 <= 3*N and j+1 <= 2*ofs) {
                (dp[i+1][j+1] += dp[i][j]) %= M;
            }
            if(i+2 <= 3*N and j-1 >= 0) {
                (dp[i+2][j-1] += dp[i][j] * (3*N-i-1)) %= M;
            }
            if(i+3 <= 3*N) {
                ll m = (3*N-i-1) * (3*N-i-2);
                (dp[i+3][j] += dp[i][j] * m) %= M;
            }
        }
    }

    ll ans = 0;
    for(int i=ofs; i<=ofs+3*N; i++) (ans += dp[3*N][i]) %= M;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 561536
a, b = map(int, input().split())
numberslist = [2,3,4,5,6,7,8,9,10,11,12,13,1]
indexofa = numberslist.index(a)
indexofb = numberslist.index(b)
if indexofa > indexofb:
    print("Alice")
elif indexofa < indexofb:
    print("Bob")
elif indexofa == indexofb :
    print("Draw")

Measured memory_bytes: 3060
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B, M =map(int, readline().split())
a = np.array(readline().split(), np.int64)
b = np.array(readline().split(), np.int64)

ans = a.min() + b.min()

for i in range(M):
  w = list(map(int, input().split()))
  new = a[w[0]-1] + b[w[1]-1] - w[2]
  ans = min(ans, new)
print(ans)

Measured memory_bytes: 34796
#include <iostream>
#include <utility> // for pair
#include <map>

std::pair<int, int> f(int n) {
  std::pair<int, int> p;
  p.first = n % 10;
  p.second = 0;
  while (n) {
    p.second = n;
    n /= 10;
  }
  return p;
}

void solve() {
  int n;
  std::map<std::pair<int, int>, int> freq;  //先頭がi, 末尾がjの整数の個数
  std::cin >> n;
  for (int i = 1; i <= n; ++i) 
    freq[f(i)] += 1;
  long long ans = 0;
  
  for (int i = 1; i <= n; ++i) {
    std::pair<int, int> p = f(i);
    std::pair<int, int> q = std::pair<int, int>(p.second, p.first);
    ans += freq[q];
  }
  std::cout << ans << std::endl;
}

int main() {
  solve();
  return 0;
}

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

using namespace std;

typedef long long ll;
#define _ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

#define sll(x) scanf("%I64d",&x)
#define sd(x)  scanf("%d",&x)
#define pll(x) printf("%I64d",x)
#define pd(x)  printf("%d",x)

#define clr(x) memset(x,0,sizeof x)

#define mid    ((l+r)>>1)
#define Pi acos(-1)
#define EPS 1e-12
#define MOD  1000000007
#define MOD1 1000000009
#define INFL 10000000000000LL
#define INF  2000000000

#define N 100005

ll ar[N],dp[N],n,k;

ll solve(int i){
if(i == n-1) return 0;
if(i>=n) return INFL;
if(dp[i] != -1 ) return dp[i];

ll ret = INFL;
for(int j=1;j<=k;j++){
  ret = min(solve(i+j)+abs(ar[i] -ar[i+j]),ret);
}
return dp[i] = ret;

}

int main()
{_
    memset(dp,-1,sizeof dp);
    cin >> n >> k;
    for(int i=0;i<n;i++) cin >> ar[i];
    cout << solve(0) ;

    return 0;
}


Measured memory_bytes: 6528
r,g,b,n = map(int,input().split())
c = 0
for i in range(n//r+1):
  for j in range((n-i*r)//g+1):
    k = (n-i*r-j*g)
    if k%b == 0 and k >= 0:
      c += 1
print(c)

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  vector<int> b(n);
  rep(i, n) cin >> b.at(i);
  vector<int> over;
  vector<int> under;
  ll overSum = 0;
  ll underSum = 0;
  rep(i, n) {
    ll diff = (ll) a.at(i) - b.at(i);
    if (diff == 0) {
      continue;
    }
    if (diff > 0) {
      overSum += diff;
      over.push_back(diff);
    } else {
      underSum += -diff;
      under.push_back(-diff);
    }
  }
  if (underSum > overSum) {
    cout << -1 << endl;
  } else {
    sort(over.rbegin(), over.rend());
    int res = under.size();
    for (int o : over) {
      if (underSum <= 0) {
        break;
      }
      res++;
      underSum -= o;
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1660
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
n, m = [int(x) for x in input().split()]
can = [True for i in range(n + 1)]
for i in range(m):
    ai = int(input())
    can[ai] = False
C = [0 for i in range(n + 1)]
for i in range(n + 1):
    if i == 0:
        C[i] = 1
    else:
        C[i] = sum(C[j] if j >= 0 and can[j] else 0 for j in (i - 1, i - 2)) % (10**9 + 7)
print(C[n])

Measured memory_bytes: 13508
#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
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;
#define debug(x) cerr << #x << ": " << (x) << "\n";

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

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

  int N, K, C;
  cin >> N >> K >> C;
  string s;
  cin >> s;

  int cnt = 0;
  int idx = 0;
  vi front;
  while (idx < s.size() && cnt <= K) {
    if (s[idx] == 'o') {
      front.pb(idx);
      idx += C+1;
      cnt++;
    } else {
      idx++;
    }
  }
  cnt = 0;
  idx = s.size() - 1;
  vi back;
  while (idx >= 0 && cnt <= K) {
    if (s[idx] == 'o') {
      back.pb(idx);
      idx -= C+1;
      cnt++;
    } else {
      idx--;
    }
  }
  reverse(All(back));
  vi ans;
  rep(i, 0, K) {
    if (front[i] == back[i]) {
      ans.pb(front[i]);
    }
  }

  for (int a: ans) {
    printf("%d\n", a+1);
  }

  return 0;
};


Measured memory_bytes: 4236
#include<queue>
#include<iostream>
#include<string>
using namespace std;
int main() {
  priority_queue<long long> Q;
  string word;
  long long k;
  while(1)
    {
      cin >> word;
      if (word == "end") break;
      else if (word == "extract") {
	cout << Q.top() << endl;
	Q.pop();
      }
      else if (word == "insert") {
	cin >> k;
	Q.push(k);
      }
    }
  return 0;
}

Measured memory_bytes: 10976
#include <bits/stdc++.h>
using namespace std;
#define data_type int
#define endl "\n"
vector<data_type> prime;
bitset<1000009>mark;
inline void sieve( data_type n)
{
    mark[0]=mark[1]=1;
    data_type i,j,limit=sqrt(n*1.0)+2;
    prime.emplace_back(2);
    for(i=4; i<=n; i+=2)
        mark[i]=1;
    for(i=3; i<=n; i+=2)
        {
            if(!mark[i])
                {
                    prime.emplace_back(i);
                    if(i<=limit)
                        {
                            for(j=i*i; j<=n; j+=i*2)
                                mark[j]=1;
                        }
                }
        }
}
int main()
{
    
    sieve(1000007);
    ios_base::sync_with_stdio(false),cin.tie(nullptr);
    data_type n,a,sum=0;
    vector<data_type>dcount(1000007),vc;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a,vc.push_back(a),dcount[a]++;
    for(int i=0; prime[i]<=1000000; i++)
        {
            sum=0;
            for(int j=prime[i]; j<=1000000; j+=prime[i])
                sum+=dcount[j];
            if(sum>1)
                break;
        }

    if(sum<=1)
        return cout<<"pairwise coprime"<<endl,0;
        
    data_type g=vc[0];
    for(int i=1; i<n; i++)
        g=__gcd(g,vc[i]);
    if(g==1)
        return cout<<"setwise coprime"<<endl,0;
        
    cout<<"not coprime"<<endl;

    return 0;

}



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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

void solve() {
    //const i64 mod = 1'000'000'007;
    
    i64 N;
    cin >> N;
    
    vector<i64> a(N);
    rep(i,0,N) cin >> a[i];
    
    vector<i64> s(N);
    s[0]=a[0];
    rep(i,1,N) s[i]=s[i-1]+a[i];
    
    auto sum=[&](i64 l,i64 r){
        i64 left=l-1<0?0:s[l-1];
        i64 right=r-1<0?0:s[r-1];
        return right-left; 
    };
    
    const i64 max=401;
    static i64 memo[max][max];
    static bool done[max][max];
    fill_n((i64*)memo,max*max,inf64);
    fill_n((bool*)done,max*max,false);
    function<i64(i64,i64)> rec=[&](i64 l,i64 r){
        auto& res=memo[l][r];
        if(done[l][r]) return res;
        done[l][r]=true;
        
        if(r-l==1) return res=0;
        
        rep(i,l,r-1){
            chmin(res,rec(l,i+1)+rec(i+1,r)+sum(l,i+1)+sum(i+1,r));
        }
        
        return res;
    };
    
    cout << rec(0,N) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(){
	int a,b,k;
	int n = 0;
	int i;
	int y[100]={};
	scanf("%d%d%d",&a,&b,&k);
	for(i=1;i<=100;i++){
		if(a%i==0 && b%i==0){
			y[n] = i;
			n++;
		}
	}
	printf("%d",y[n-k]);
	return 0;
}

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

int main()
{
  string w;
  cin >> w;
  bool a[26] = {};
  for(int i = 0; i < (int)w.size(); i++)
    a[w[i]-'a'] = !a[w[i]-'a'];
  for(int i = 0; i < 26; i++)
    if(a[i]){
      cout << "No" << endl;
      return 0;
    }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	int l1 = 0, l2 = 0, l3 = 0;
	int d = 0;
	while (1) {
		if (d == 0) {
			if (l1 < s1.size()) d = s1[l1] - 'a';
			else break;
			l1++;
		}
		else if (d == 1) {
			if (l2 < s2.size()) d = s2[l2] - 'a';
			else break;
			l2++;
		}
		else {
			if (l3 < s3.size()) d = s3[l3] - 'a';
			else break;
			l3++;
		}
	}
	cout << (char)(d + 'A') << endl;
	return 0;
}

Measured memory_bytes: 256
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 15
#define fi(a, b, c, d) for(int a = b; i < c; i += d)
#define fl(a, b, c, d) for(ll a = b; i < c; i += d)

ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
string S = "";

int main() {
	cin >> S;
	if(S.size() & 1) {
		printf("No\n");
		exit(0);
	}
	if(S[0] != 'h') {
		printf("No\n");
		exit(0);
	}
	fi(i, 1, S.size(), 1) {
		if(i % 2) {
			if(S[i] != 'i') {
				printf("No\n");
				exit(0);
			}
		}
		else {
			if(S[i] != 'h') {
				printf("No\n");
				exit(0);
			}
		}
	}
	printf("Yes\n");
	return 0;
}
/*
	Powered by Buggy Plugin
*/




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

#define debug(x) cout <<"DEBUG"<<" "<<#x<<":"<<x<<'\n'

//↓0-indexか1-indexでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-index昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-index昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-index降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-index降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    //cin.tie(nullptr);
    //ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(15);

    int n;
    while(cin >> n) {
        if(!n) break;
        int cnt = 0;
        rep(i,n/4) {
            int p; cin >> p;
            cnt += p;
        }
        cout << cnt << '\n';
    }
}


Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
  int a;
  char s[11];
  cin>>a>>s;
  if(a>=3200){
    cout<<s;
    return 0;
  }else{
    cout<<"red";
  }
  return 0;
}

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

int main() {
  int a;
  cin >> a;
  int h = 0;
  while(a > 4) {
    if(a >= 500) {
      int n = a / 500;
      a = a % 500;
      h = h + (n * 1000);
    } else {
      int m = a / 5;
      a = a % 5;
      h = h + (m * 5);
    }
  }
  cout << h << endl;
}

Measured memory_bytes: 3516
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {

	int count = 0;
	int input[20];
	int counter = 0;

	scanf("%d", &count);
	for (int i = 0; i < count; i++) {
		scanf("%d", &input[i]);
	}


	for (int i = 0; i < (count - 2); i++) {
		if ((input[i + 1] > input[i + 2]) && (input[i + 1] < input[i]) ||
			(input[i + 1] < input[i + 2]) && (input[i + 1] > input[i])) {
			counter += 1;
		}
	}

	printf("%d", counter);
	return 0;
}

Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vll a(n),b(n),c(n);
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> b[i];
    REP(i,n) cin >> c[i];
    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));
    vll bc(n);
    REP(i,n){
        ll ok = n;
        ll ng = -1;
        while(abs(ok-ng)>1){
            ll mid = (ok+ng)/2;
            if(b[i]<c[mid]){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        bc[i] = n-ok;
    }
    vll bcsum(n+1,0);
    for(ll i=n-1;i>=0;--i){
        bcsum[i] = bcsum[i+1]+bc[i];
    }
    ll ans = 0;
    REP(i,n){
        ll ok = n;
        ll ng = -1;
        while(abs(ok-ng)>1){
            ll mid = (ok+ng)/2;
            if(a[i]<b[mid]){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        ans += bcsum[ok];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7124