akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define int long long

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "YES"
#define FALSE__ "NO"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

vector<string> v;
int N, L;

signed main()
{
	cin >> N >> L;
	rep(i, N) {
		CIN(string, s);
		v.PB(s);
	}
	sort(all(v));
	for (string s : v) cout << s;
	cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int h,w,n;
    cin>>h>>w>>n;
    vector<int> ans;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        for(int k=0;k<a;k++){
            ans.push_back(i+1);
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(i%2==0){
                cout<<ans[w*i+j]<<" ";
            }
            else{
                cout<<ans[w*i+w-j-1]<<" ";
            }
        }
        cout<<endl;
    }
}


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

    using namespace std;
    template <typename T>
    void debug(string t, T input) {
        cout<<t<<"-> "<<input<<"\n";
    }
    template <typename T>
    void debug(int i,string t, T input) {
        cout<<"Case#"<<i<<" "<<t<<"-> "<<input<<"\n";
    }

    int main(){
        int k,a,b;
        cin>>k>>a>>b;
        for(int i=a;i<=b;i++){
            if(i%k==0){
                cout<<"OK";
                return 0;
            }
        }
        cout<<"NG";
        return 0;
    }


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

void exportVector(vector<int> A){
    // ソート前の配列の確認
    rep(i,A.size()){
        if(i == A.size() - 1){
            cout << A.at(i) << endl;            
        }
        else{
            cout << A.at(i) << " ";
        }
    }
}

// P.54
// N個の要素を含む0-オリジンの配列A
void insertionSort(vector<int> &A, int N){
    for(int i = 1; i < N; i++){
        int v = A.at(i);
        int j = i - 1;
        while(j >= 0 && A.at(j) > v){
            A.at(j+1) = A.at(j);
            j--;
        }
        A.at(j+1) = v;
        exportVector(A);
    }
} 

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    rep(i,n){
        cin >> A.at(i);
    }


    // ソート前の配列の確認
    exportVector(A);

    // 挿入ソート
    insertionSort(A, n);
    return 0;
}


Measured memory_bytes: 3164
L, R = [int(_) for _ in input().split()]

ans = 2020
r = min(L + 2019, R)
for i in range(L, r + 1):
    for j in range(i + 1, r + 1):
        x = (i % 2019) * (j % 2019)
        x %= 2019
        ans = min(x, ans)
print(ans)


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

using namespace std;
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

	
int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b,k;
	cin >>a >>b >>k;
	
	set<int> st;
	
	rep(i,k){
		if(a+i <=b) st.insert(a+i);
	}
	rep(i,k){
		if(b-i >=a) st.insert(b-i);
	}
	for(auto x :st) printf("%d\n",x); 
	return 0;
	
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
As.sort(reverse=True)
from heapq import heappush, heappop

first = (As.pop(0))
hq = []
if N<2:
    print(0)
else:
    ans = 0
    second = As.pop(0)
    ans += first
    heappush(hq, (-second, -first))
    heappush(hq, (-second, -first))
    for a in As:
        s, f = heappop(hq)
        ans -= s
        heappush(hq, (-a, s))
        heappush(hq, (-a, f))

print(ans)

Measured memory_bytes: 107180
import numpy as np


def main():
    H, W, A, B = map(int, input().split())
    s = np.zeros((H, W), dtype=np.int64)
    s[:B, :A] = 1
    s[B:, A:] = 1
    
    for l in s:
        print(*l, sep='')


if __name__ == "__main__":
    main()

Measured memory_bytes: 35292
#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair <int,int> PAIR;
const int N = 1e5+5;
const ll M = 11092019;

ll c[15],p[15][15],temp[15];

inline bool check(int m,ll x){
	for(int i = 1;i <= m;++i){
		if(temp[i] < x) return 0;
	}
	return 1;
}

int main() {
	int n,m,x;
	scanf("%d%d%d",&n,&m,&x);
	
	for(int i = 0;i < n;++i){
		scanf("%lld",&c[i]);
		for(int j = 1;j <= m;++j)
			scanf("%lld",&p[i][j]);
	}
	
	ll ans = 2e18;
	for(int base = 0;base < (1 << n);++base){
		ll cnt = 0;
		memset(temp,0,sizeof(temp));
		for(int i = 0;i < n;++i){
			if((1 << i) & base){
				cnt += c[i];
				for(int j = 1;j <= m;++j)
					temp[j] += p[i][j];
			}
		}
		//printf("%d %lld\n",base,cnt);
		if(check(m,x)) ans = min(ans,cnt);
	}
	
	if(ans == 2e18) printf("-1\n");
	else printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define N 1010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)	for(int i = n - 1; i >= 0; --i)
#define forr1(i, n)	for(int i = n; i >= 1; --i)
#define form(l, r, i)	for(int i = l; i <= r; ++i)
#define forv(r, l, i)	for(int i = r; i >= l; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
 
const ll inf = 1e18 + 7;
const lld EPS = 0.00000001;

using namespace std;



int main() 
{
	barnarnar
	string a;
	cin >> a;
	forn(i, a.si)
	{
		if(i % 2 == 0 && a[i] != 'h')
		{
			cout << "No";
			r0;
		}
		if(i % 2 == 1 && a[i] != 'i')
		{
			cout << "No";
			r0;
		}
	}
	if(a.si % 2 == 0)	cout << "Yes";
	else	cout << "No";
	return 0;
}








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


int main(){
    ll x, y;
    cin >> x >> y;

    int cnt = 0;
    while(x<=y){
        cnt++;
        x*=2;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <map>
#include <algorithm>
#include <stack>
#include <set>
//反向bfs
using namespace std;
map<string ,int> t;
int num;
int mv[]={-4,4,1,-1};//上下右左
void bfs(string st)
{
    queue<string> q;
    t[st]=1;
    q.push(st);
    while(!q.empty())
    {

       st=q.front(),q.pop();
//        int nu=st.find('0');
//        for(int i=0;i<4;i++)
//        {
//            int tn=nu+mv[i];
//            if(tn<0||tn>7||tn==3&&mv[i]==1||tn==4&&mv[i]==-1)
//                continue;
//                string tp=st;
//            swap(tp[nu],tp[nu+mv[i]]);
//            if(!t[tp])
//            {
//                    q.push(tp);
//                    t[tp]=t[st]+1;
//            }
//
//
//        }
//        }
//

   // t[st]=1;q.push(st); //起始状?
  //  while(!q.empty())
  //  {
        //st=q.front();q.pop();
        int num=st.find('0');//找到空格位置
        for(int i=0;i<4;++i)
        {
            int tn=num+mv[i];//可能??的数?
            if(tn<0||tn>7||num==3&&mv[i]==1||num==4&&mv[i]==-1)
            //空格在3的?候，4不能??，因?3 4 不相?，反之同理
            {
                continue;
            }
            string tp=st;
            swap(tp[num],tp[num+mv[i]]);//移?物?
            if(!t[tp])//未出??的状?
            {
                q.push(tp);
                t[tp]=t[st]+1;
            }
        }
    }
}

int main()
{
    string st="01234567";
    bfs(st);
    while(scanf("%d",&num)!=EOF)
    {
        st[0]=num+'0';
        for(int i=1;i<8;i++)
        {
            scanf("%d",&num);
            st[i]=num+'0';
        }
        cout<<t[st]-1<<endl;
    }

}

Measured memory_bytes: 5388
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
#define fisrt fir
#define second sec

int n, x, a[105];

int main(){
	scanf(" %d %d", &n, &x);
	for(int i = 1; i <= n; i ++) scanf(" %d", &a[i]);
	sort(a + 1, a + n + 1);
	int cnt = 0;
	for(int i = 1; i <= n; i ++){
		if(i == n && x > a[i]) break;
		if(x >= a[i]){
			x -= a[i];
			cnt ++;
		}
	}
	printf("%d\n", cnt);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3+7;
const ll mod = 1e9+7;
const int sz = 62;
#define afdafafafdafaf y1;
int n,m;

int main()
{
    scanf("%d", &n);
    vector<int> arr[maxn];
    for(int i=1;i<=n;i++){
        for(int j=0;j<n-1;j++){
            int x;
            scanf("%d", &x);
            arr[i].push_back(x);
        }
        reverse(arr[i].begin(), arr[i].end());
    }
    int ins=0, ans=0, sum=0,i=0;
    set<int> s;
    for(int i=1;i<=n;i++){
        if(arr[i].size() > 0 && arr[arr[i].back()].back() == i && s.count(arr[i].back()) == 0){
            s.insert(i);
            s.insert(arr[i].back());
        }
    }
    while(sum<n*(n-1)){
        set<int> mid;
        ins = 0;
        for(int x : s){
            arr[x].pop_back();
            ins += 1;
        }
        for(int x : s){
            if(arr[x].size() > 0 && arr[arr[x].back()].size() > 0 && arr[arr[x].back()].back() == x && 
                    mid.count(arr[x].back())==0){
                mid.insert(x);
                mid.insert(arr[x].back());
            }
        }
        s = mid;
        sum += ins;
        if(ins==0){
            break;
        }
        ans++;
    }
    if(sum<n*(n-1))ans = -1;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 4352
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-TypicalStairs.py
#
N, M = map(int, input().split())
arr = [int(input()) for _ in range(M)]
MOD = 10**9 + 7
stairs = [True for _ in range(0, N+1)]
for x in arr:
    stairs[x] = False

dp = [0 for _ in range(N+1)]

dp[0] = 1 if 0 not in arr else 0
dp[1] = 1 if 1 not in arr else 0

for i in range(2, N+1):
    if dp[i-1] == 0 and dp[i-2] == 0:
        break
    if stairs[i-1]: dp[i] += dp[i-1]
    if stairs[i-2]: dp[i] += dp[i-2]

    dp[i] %= MOD

print(dp[-1] % MOD)



Measured memory_bytes: 9612
import java.util.Scanner;
public class Main
{
	public static void main(String args[])
	{
		int w, h, x, y, r;
		Scanner input = new Scanner(System.in);
		w = input.nextInt();
		h = input.nextInt();
		x = input.nextInt();
		y = input.nextInt();
		r = input.nextInt();
		if(x+r <= w && x-r >= 0 && y+r <= h && y-r >= 0)
			System.out.println("Yes");
		else 
			System.out.println("No");
	}
}

Measured memory_bytes: 26416
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<typeinfo>

using namespace std;
#define REP(i,m,n) for(int i=m;i<n;++i)
#define REPll(i,m,n) for(ll i=m;i<n;++i)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

int main(){
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1)*(n - w + 1) << endl;
	return 0;
}

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

using namespace std;

int main() {
    int N;
    string str;
    cin >> N;
    cin >> str;
    
    vector<int> vec(2, 0);
    int counter=0;
    for(int n=0; n<N; n++) {
        if(counter==0) {
            if(str[n]=='(') {
                vec[1]++;
                counter++;
            } else {
                vec[0]++;
                counter--;
            }
        } else if(counter>0) {
            if(str[n]=='(') {
                vec[1]++;
                counter++;
            } else {
                vec[1]--;
                counter--;
            }
        } else {
            if(str[n]=='(') {
                vec[1]++;
                counter=1;
            } else {
                vec[0]++;
                counter--;
            }
        }
    }
    
    for(int vi=0; vi<2; vi++) {
        for(int lr=0; lr<vec[vi]; lr++) {
            if(vi==0) {
                str = '('+str;
            } else {
                str = str+')';
            }
        }
    }
    
    cout << str << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
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() {
    vector<int>a(5);
    rep(i,5) {
        cin >> a[i];
    }
    int ans = 1000;
    do{
        int sum = 0;
        rep(i,5) {  
            if(i==4) {
                sum += a[i];
                break;
            }    
            if(a[i]%10!=0)sum += a[i] + 10-a[i]%10;
            if(a[i]%10==0)sum += a[i];
        }
        ans = min(ans,sum);
    } while(next_permutation(a.begin(),a.end()));
    cout << ans << endl;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
n = gets.to_i
a = gets.split.map(&:to_i)

sums = Array.new(n,0)
sums[0] = a[0]
for i in 1..(n-1)
  sums[i] = sums[i-1] + a[i]
end

ans = 0
for i in 1..(n-1)
  id = n-i
  ans += (a[id] * sums[id-1]) % MOD
  ans = ans % MOD
end
puts ans

Measured memory_bytes: 35456
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main(void){
    // Your code here!
    int n;
    
    cin >> n;
    
    if(n < 1200)
        cout << "ABC" << endl;
    else if(n < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1000100100;

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

    vector<bool> flag((int)'z' - (int)'a' + 1, false);
    REP(i, S.length()) {
        int id = (int)S[i] - (int)'a';
        if(flag[id]) {
            cout << "no" << endl;
            return 0;
        }
        flag[id] = true;
    }

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

Measured memory_bytes: 3628
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int ho[4][3][11];
    int x,y,z,n,m,b,f,r,v;
    for(x = 0 ; x < 4 ; x ++){
        for(y = 0 ; y < 3 ; y++){
            for(z = 0 ; z < 10 ; z++){
                ho[x][y][z] = 0;
            }
        }
    }
    scanf("%d",&n);
    for(m = 0 ; m < n ; m++){
        scanf("\n");
        scanf("%d %d %d %d",&b,&f,&r,&v);
        if(b == 1){
            if(f == 1){
                ho[0][0][r-1] += v;
            }else if(f == 2){
                ho[0][1][r-1] += v;
            }else{
                ho[0][2][r-1] += v;
            }
        }else if(b == 2){
            if(f == 1){
                ho[1][0][r-1] += v;
            }else if(f == 2){
                ho[1][1][r-1] += v;
            }else{
                ho[1][2][r-1] += v;
            }
        }else if(b == 3){
            if(f == 1){
                ho[2][0][r-1] += v;
            }else if(f == 2){
                ho[2][1][r-1] += v;
            }else{
                ho[2][2][r-1] += v;
            }
        }else{
            if(f == 1){
                ho[3][0][r-1] += v;
            }else if(f == 2){
                ho[3][1][r-1] += v;
            }else{
                ho[3][2][r-1] += v;
            }
        }
    }
    for(x = 0 ; x < 4 ; x ++){
        for(y = 0 ; y < 3 ; y++){
            for(z = 0 ; z < 10 ; z++){
                printf(" %d",ho[x][y][z]);
            }
            printf("\n");
        }
        if(x != 3){
            printf("####################\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_N = 1 << 18;
struct BIT{
  int bit[MAX_N+1],n;
  BIT(){init();}
  BIT(int n):n(n){init();}
  void init(){
    memset(bit,0,sizeof(bit));
  }
  int sum(int i){
    int s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
  void add(int i,int x){
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
  int sum0(int i){
    return sum(i+1);
  }
  void add0(int i,int x){
    add(i+1,x);
  }
};
signed main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  int b[n];
  for(int i=0;i<n;i++) b[i]=a[i];
  sort(b,b+n);
  map<int,int> m;
  for(int i=0;i<n;i++) m[b[i]]=i+1;
  BIT bit(n);
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=i-bit.sum(m[a[i]]);
    bit.add(m[a[i]],1);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 20784
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    d = dict()
    for i in range(1, n + 1):
        d[i] = input_int_list()[::-1]
    day = 0
    candi = set(range(1, n + 1))
    rest = (n * (n - 1)) // 2
    while rest:
        played = set()
        for a in candi:
            if d[a] and d[d[a][-1]][-1] and a == d[d[a][-1]][-1]:
                played.add(a)
                played.add(d[a][-1])

        if not played:
            break

        candi.clear()

        rest -= len(played) // 2
        for a in played:
            candi.add(a)
            d[a].pop()
            # if d[a]:
            #     candi.add(d[a][-1])
        day += 1

    if rest == 0:
        print(day)
    else:
        print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 86196
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll fact(ll n)
{
    if (n > 1)
        return n * fact(n - 1);
    else
        return 1;
}
bool sortbysec(const tuple<int, int, int> &a,
               const tuple<int, int, int> &b)
{
    return (get<1>(a) < get<1>(b));
}
int last_digit(int n)
{
    int ans = 0;
    while (n != 0)
    {
        ans = n % 10;
        n /= 10;
    }
    return ans;
}
int main()
{
    fastio();
    string s;
    cin >> s;
    if (s == "SSS")
    {
        cout << "0\n";
    }
    else if (s == "SSR")
    {
        cout << "1\n";
    }
    else if (s == "SRR")
    {
        cout << "2\n";
    }
    else if (s == "SRS")
    {
        cout << "1\n";
    }
    else if (s == "RSS")
    {
        cout << "1\n";
    }
    else if (s == "RRS")
    {
        cout << "2\n";
    }

    else if (s == "RSR")
    {
        cout << "1\n";
    }
    else if (s == "RRR")
    {
        cout << "3\n";
    }
}


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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll H,W;cin>>H>>W;
  vector<string> S(H);
  for(ll i=0;i<H;i++){
    cin>>S[i];
  }

  ll suml[H][W]={},sumr[H][W]={};
  ll sumu[H][W]={},sumd[H][W]={};
  for(ll i=0;i<H;i++){
    suml[i][0]=S[i][0]=='.';
    for(ll j=0;j+1<W;j++){
      suml[i][j+1]=suml[i][j]+1;
      if(S[i][j+1]=='#'){
        suml[i][j+1]=0;
      }
    }
    sumr[i][W-1]=S[i][W-1]=='.';
    for(ll j=W-1;j>0;j--){
      sumr[i][j-1]=sumr[i][j]+1;
      if(S[i][j-1]=='#'){
        sumr[i][j-1]=0;
      }
    }
  }
  for(ll j=0;j<W;j++){
    sumu[0][j]=S[0][j]=='.';
    for(ll i=0;i+1<H;i++){
      sumu[i+1][j] = sumu[i][j]+1;
      if(S[i+1][j]=='#'){
        sumu[i+1][j]=0;
      }
    }
    sumd[H-1][j]=S[H-1][j]=='.';
    for(ll i=H-1;i>0;i--){
      sumd[i-1][j] = sumd[i][j]+1;
      if(S[i-1][j]=='#'){
        sumd[i-1][j] = 0;
      }
    }
  }
  ll ans = 0;
  for(ll i=0;i<H;i++){
    for(ll j=0;j<W;j++){
      if(S[i][j]=='.'){
        ans = max(ans,suml[i][j]+sumr[i][j]+sumu[i][j]+sumd[i][j]-3);
        /*
        debug(i);
        debug(j);
        debug(suml[i][j]);
        debug(sumr[i][j]);
        debug(sumu[i][j]);
        debug(sumd[i][j]);
        debug(suml[i][j]+sumr[i][j]+sumu[i][j]+sumd[i][j]-3);
        */
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 129536
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  rep(i,3){
    if(n%10==7){
      cout<<"Yes"<<'\n';
      return(0);
    }
    n/=10;
  }
  cout<<"No"<<'\n';
  return(0);
}


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

const int INF = 1e18L + 5;

int32_t main()
{
	int n,wt;
	cin>>n>>wt;
	vector<int> w(n),v(n);
	for(int i=0; i<n; i++)
		cin>>w[i]>>v[i];
	int sum=accumulate(v.begin(),v.end(),0);
	vector<int> dp(sum+1,INF);  // dp[i] - the minimum total weight of items with total value exactly i 
	dp[0]=0;
	for(int j=0; j<n; j++)
	{
	for(int i=sum-v[j]; i>=0; i--)
	{
		dp[i+v[j]]=min(dp[i+v[j]],dp[i]+w[j]);
	}
	} 
	int ans=0;
	for(int i=1; i<=sum ; i++)
		{
			if(dp[i]<=wt)
				ans=max(ans,i);
		}
	cout<<ans;
	return 0;
}


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

using namespace std;

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

  if (min(a, b) < c && c < max(a, b)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
N,K =map(int,input().split())
D = []
A = []
for _ in range(K):
    D.append(int(input()))
    A.append(list(map(int,input().split())))
    
sunuke = [0]*N
for i in range(K):
    for j in range(D[i]):
        sunuke[A[i][j]-1] += 1
answer = sunuke.count(0)
print(answer)

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

using namespace std;

typedef long long LL;

LL f[20];

LL p[20];

int main(){
    LL n;scanf("%lld",&n);

    f[0]=1;
    for(int i=1;i<=12;++i)f[i]=26ll*f[i-1];
    for(int i=2;i<=12;++i)f[i]+=f[i-1];

    p[0]=1;
    for(int i=1;i<=12;++i)p[i]=26ll*p[i-1];

    int idx=1;
    while(f[idx]<n)++idx;

    string res;

    LL cnt;
    if(idx==1)cnt=0;
    else cnt=f[idx-1];

    for(int i=1;i<=idx;++i){
        for(int ch=0;ch<=25;++ch){
            LL t=cnt+1ll*(ch+1)*p[idx-i];
            if(t>=n){
                res+=ch+'a';
                cnt+=1ll*ch*p[idx-i];
                break;
            }
        }
    }

    cout<<res;

    return 0;
}


Measured memory_bytes: 3688
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<=n;i++)
typedef int long long ll;
using namespace std;

int main(){
    string a,b;
    cin>>a>>b;
    a+=b;
    int aa=atoi(a.c_str());
    for(int i=1;i<=sqrt(aa);i++){
        if(i*i==aa){
            cout<<"Yes"<<endl;
            return 0;
        }
        
    }
    cout<<"No"<<endl;
   
return 0;
}

Measured memory_bytes: 256
def main():
    n, k = [int(e) for e in input().split()]
    V = [int(e) for e in input().split()]

    ans = 0
    vc = min(n, k)
    for vci in range(1, vc + 1):
        for vcii in range(vci + 1):
            Hand = []
            for li in range(vcii):
                Hand.append(V[li])

            for ri in range(vci - vcii):
                Hand.append(V[-ri - 1])

            Hand.sort()
            for i in range(min(k - vci, len(Hand))):
                if Hand[i] < 0:
                    Hand[i] = 0

            ans = max(sum(Hand), ans)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41840
object Main extends App {

  import scala.io.StdIn._

  val Array(x, y) = readLine.trim.split(' ').map(_.toInt)
  println(x + y / 2)
  implicit class ScopeFunc[T](val value: T) {
    def let[A](func: T ⇒ A): A = func(value)
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}

/*
 */

Measured memory_bytes: 25528
//By : BebekJK
#include<bits/stdc++.h>

#define endl '\n'
#define MOD 1000000007
#define PI 3.141592653
#define fi first
#define sc second
#define pb push_back
#define pbb pop_back

//#pragma GCC optimize("Ofast")
//#pragma GCC target ("string"...)
//#pragma GCC push_options
//#pragma GCC pop_options
//#pragma GCC reset_options
//#pragma GCC optimize ("O3")

using namespace std;
typedef long long ll;
typedef long long ld;
typedef pair<int , int> pii;
typedef pair<long long , long long> pll;

void BOOST(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
}
void fcin(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c=='-'){
		neg = true;
		c = getchar();
	}
	for(;(c>47 && c<58);c=getchar())x = (x<<1)+(x<<3)+c-48;
	if(neg)x*=-1;
}
ll pmod(ll a , ll b){
	if(b==0)return 1;
	ll temp = pmod(a , b/2);
	if(b%2==0)return(temp*temp)%MOD;
	return (((temp*temp)%MOD)*a)%MOD;
}
int n , h[100005];
int memo[100005];
int solve(int idx){
	if(idx == n) return 0;
	if(memo[idx]!=-1)return memo[idx];
	if(idx + 1 == n)return memo[idx] = solve(idx+1) + abs(h[idx+1]-h[idx]);
	else return memo[idx] = min(solve(idx+1) + abs(h[idx+1]-h[idx]) , solve(idx+2) + abs(h[idx+2] - h[idx]));
}
int main(){
//	BOOST();
	cin>>n;	
	for(int i=1;i<=n;i++)cin>>h[i];
	memset(memo , -1 , sizeof memo);
	cout<<solve(1)<<endl;
}







Measured memory_bytes: 2560
// WARNING: Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

// Macro
#define REP(i, N) for(int i=0; i<(int)N; i++)
#define REPR(i, N) for(int i=(int)N-1; i>=0; i--)
#define mp make_pair
#define pb push_back

// Type
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;

// Constants
const ll MOD = 1000000007;

/**
  型に合わせたINFを返す
  int: 214,748,364 (2.14 * 1e8)
  ll : 922,337,203,685,477,580 (9.22 * 1e17)
*/
template <typename T>
T getINF() {
  // NOTE: INF同士を足してもオーバーフロー起こさないように、10で割っている
  return numeric_limits<T>::max() / 10;
}

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

/**
  辺
  to: 辺の行き先
  cost: 辺の重み
  T: 重みの型
*/
template <typename T>
struct Edge {
  int to;
  T cost;
  Edge(int to, T cost) : to(to), cost(cost) {}
};

/**
  n: 頂点数
  graph: グラフ本体
*/
template <typename T>
class Graph {
  public:
    int n;
    vector< vector< Edge<T> > > graph;

    Graph(int n) {
      this->n = n;
      this->graph.assign(n, vector< Edge<T> >());
    }

    void addEdge(int from, int to, T cost) {
      this->graph[from].push_back(Edge<T>(to, cost));
    }
};

Graph<int> g(100000);
int color[100000];

void dfs(int p, int c) {
  color[p] = c;
  for(Edge<int> edge : g.graph[p]) {
    if(edge.cost%2==0 && color[edge.to]==0) dfs(edge.to, c);
    else if(color[edge.to]==0) dfs(edge.to, -c);
  }
}

int main() {
  REP(i, 100000) color[i] = 0;

  int n;
  cin >> n;
  REP(i, n-1) {
    int u, v;
    ll w;
    cin >> u >> v >> w;
    g.addEdge(u-1, v-1, (int)(w%2));
    g.addEdge(v-1, u-1, (int)(w%2));
  }

  dfs(0, 1);

  // REP(i, n) cout << color[i] << endl;
  REP(i, n) {
    if(color[i] == 1) cout << 1 << endl;
    else cout << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N;
  cin >> N;
  if (N == 1) {
    cout << "Hello World" << endl;
    return 0;
  }
  int A, B;
  cin >> A >> B;
  cout << A + B << endl;

  return 0;
}

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

char dx[]{'#','#','.','.'},dy[]{'#','.','#','.'};
int main(){
	int n;scanf("%d",&n);
	string s1,s2;
	bool flag=true;
	while(1){
		if(flag){
			flag=false;
			rep(i,4){
				string s3=s1+dx[i],s4=s2+dy[i];
				cout<<s3<<endl<<s4<<endl;
				string res;cin>>res;
				if(res=="end")return 0;
				if(res=="T"){
					s1=s3;s2=s4;
					flag=true;
					break;
				}
			}
		}
		else{
			rep(i,4){
				string s3=dx[i]+s1,s4=dy[i]+s2;
				cout<<s3<<endl<<s4<<endl;
				string res;cin>>res;
				if(res=="end")return 0;
				if(res=="T"){
					s1=s3;s2=s4;
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 720
import fractions
n,x=map(int,input().split())
if n==1:
  print(abs(x-int(input())))
  exit()
l=list(map(int,input().split()))
l.append(x)
l.sort()
l2=[]
for i in range(1,n+1):
  l2.append(l[i]-l[i-1])
a=10000000000
for i in range(len(l2)-1):
  b=fractions.gcd(l2[i],l2[i+1])
  if b<a:
    a=b
print(a)


Measured memory_bytes: 16240
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace lineAralgebra
{
	class Program
	{
		static int[] x = { -1, 0, 1, 0, -1, 1, 1, -1, };
		static int[] y = { 0, 1, 0, -1, -1, 1, -1, 1 };
		static int h = 0;
		static int w = 0;
		static void Main(string[] args)
		{
			while (true)
			{
				var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
				w = input[0];
				h = input[1];
				if (h == 0 && w == 0)
				{
					break;
				}
				var map = new int[h, w];
				var visited = new bool[h, w];
				var ans = 0;

				for (int i = 0; i < h; i++)
				{
					input = Console.ReadLine().Split().Select(int.Parse).ToArray();
					for (int j = 0; j < input.Length; j++)
					{
						map[i, j] = input[j];
					}
				}

				for (int i = 0; i < h; i++)
				{
					for (int j = 0; j < w; j++)
					{
						if (visited[i, j] || map[i, j] == 0) continue;
						Dfs(map, visited, i, j);
						ans++;
					}
				}
				Console.WriteLine(ans);
			}
		}

		static void Dfs(int[,] map, bool[,] visited, int currentY, int currentX)
		{
			visited[currentY, currentX] = true;
			for (int i = 0; i < x.Length; i++)
			{
				var nextY = y[i] + currentY;
				var nextX = x[i] + currentX;
				if (nextX < 0 || nextX >= w || nextY < 0 || nextY >= h || visited[nextY, nextX] || map[nextY, nextX] == 0) continue;
				Dfs(map, visited, nextY, nextX);
			}
		}
	}
}


Measured memory_bytes: 16532
S  = input()
MM = ['%02i' % mm for mm in range(1, 12+1)]

if S[:2] in MM:
    if S[2:] in MM:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if S[2:] in MM:
        print('YYMM')
    else:
        print('NA')


Measured memory_bytes: 2940
n, m = map(int, input().split())
edges = [[] for i in range(n)]
for i in range(m):
    li, ri, di = map(int, input().split())
    li, ri = li-1, ri-1
    edges[li].append((ri, di))
    edges[ri].append((li, -di))

coordinate = [None for i in range(n)]
for i in range(n):
    if coordinate[i] == None:
        coordinate[i] = 0
    else:
        continue
    nodes = [i]
    while nodes != []:
        next_nodes = []
        for node in nodes:
            edge = edges[node]
            start = coordinate[node]
            for end, dist in edge:
                if coordinate[end] == None:
                    coordinate[end] = start + dist
                    next_nodes.append(end)
                else:
                    if coordinate[end] != start + dist:
                        print('No')
                        exit()
        nodes = next_nodes[:]
print('Yes')

Measured memory_bytes: 85280
N = int(input())
A = sorted([a for a in map(int,input().split())], reverse=True)

flag = 0
Alice = 0
Bob = 0
for a in A:
    if flag==0:
        Alice += a
        flag = 1
    elif flag==1:
        Bob += a
        flag = 0
print(abs(Alice-Bob))

Measured memory_bytes: 3064
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {

        long[] inp = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

        long n, a, b;
        n = inp[0]; a = inp[1]; b = inp[2];

        long ans = 0,tmp=0;

        ans = a * (n / (a + b));
        tmp= n % (a + b);
        ans += Math.Min(tmp, a);

        Console.WriteLine(ans);

    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;

  vector<int> H(N);
  for(int i=0; i<N; i++){
    cin >> H[i];
  }
  sort(H.begin(), H.end());

  int min = int(1e9);
  for(int i=0; i<=N-K; i++){
    if (H[i+K-1] - H[i] < min){
      min = H[i+K-1] - H[i];
    }
  }
  cout << min << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

const ll maxN = 1e5 + 11;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

void build(ll node, ll start, ll end){
	if(start == end)
		segtree[node] = A[start];
	else{
		ll mid = (start + end)/2;
		build(left(node), start, mid);
		build(right(node), mid+1, end);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

void update(ll node, ll start, ll end, ll idx, ll val){
	if(start == end)
		segtree[node] += val;
	else{
		ll mid=(start + end)/2;
		if(idx <= mid)
			update(left(node), start, mid, idx, val);
		else
			update(right(node), mid+1, end, idx, val);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

ll sums(ll node, ll start, ll end, ll l, ll r){
	if(l > end or r < start or start > end)
		return 0;
	if(l <= start and r >= end)
		return segtree[node];
	ll mid = (start+end)/2;
	return sums(left(node), start, mid, l , r) + sums(right(node), mid + 1, end, l , r);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	double a, b;
	cin >> a >> b;
	cout << fixed << setprecision(6) << a/b;
	return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
long long n, a, b, c, d;
map<long long, long long>mp;
set<long long>s;
long long solve(long long x){
	s.insert(x);
	if(x==0) return 0;
	if(mp[x]) return mp[x];
	long long ans1;
	if(1e18/x<d) ans1=1e18;
	else ans1=x*d;
	long long ans2=solve((x-(x%2))/2)+a+(x%2)*d;
	if(x!=2) ans2=min(ans2, solve((x+2-(x%2))/2)+a+(2-x%2)*d);
	long long ans3=solve((x-(x%3))/3)+b+(x%3)*d;
	if(x!=3) ans3=min(ans3, solve((x+3-(x%3))/3)+b+(3-x%3)*d);
	long long ans4=solve((x-(x%5))/5)+c+(x%5)*d;
	if(x!=5) ans4=min(ans4, solve((x+5-(x%5))/5)+c+(5-x%5)*d);
	return mp[x]=min({ans1, ans2, ans3, ans4});
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T;
	cin>>T;
	while(T--){
		cin>>n>>a>>b>>c>>d;
		for(long long i:s) mp[i]=0;
		mp[0]=0;
		mp[1]=d;
		cout<<solve(n)<<"\n";
	}
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)

void FIO()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int n;
int a[405];
int prefs[405];
int dp[405][405];

int prefix_sum(int i, int j)
{
	if (i == 0)
		return prefs[j];
	return
	    prefs[j] - prefs[i - 1];
}

int solve(int i, int j)
{
	if (i >= j)
		return 0;

	if (dp[i][j] != -1)
		return dp[i][j];

	dp[i][j] = LLONG_MAX;

	for (int k = i; k <= j; k++)
	{
		dp[i][j] = min(dp[i][j], solve(i, k) + solve(k + 1, j) + prefix_sum(i, k) + prefix_sum(k + 1, j));
	}

	return dp[i][j];
}

int32_t main()
{
	FIO();
	cin >> n;
	memset(dp, -1, sizeof(dp));

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

	prefs[0] = a[0];

	for (int i = 1; i < n; i++)
		prefs[i] = a[i] + prefs[i - 1];

	int	ans = solve(0, n - 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4892
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
#define REP(i, d, n) for(int i=(d); i<(n); i++)
typedef long long ll;
const int mod = 1e9 + 7;
int main() {

    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    int water[3000];
    int idx1 = 0;
    for(int i=0; i<=f; i++){
        for(int j=0; j<=f; j++){
            int x = 100 * a * i + 100 * b * j;
            if(x <= f){
                water[idx1++] = x;
            }
        }
    }
    int suger[100000];
    int idx2 = 0;
    for(int i=0; i<=f; i++){
        for(int j=0; j<=f; j++){
            int y = c * i + d * j;
            if(y + 100*(y/100) <= f){
                suger[idx2++] = y;
            }
        }
    }

    double ans = 0;
    int suger_water = 100 * a, ans_suger = 0;
    double base = (double) e / (double) (100 + e);
    rep(i, idx1){
        rep(j, idx2){
            int tmp = water[i] + suger[j];
            if(tmp > f){
                continue;
            }
            double res = (double) suger[j] / (double) tmp;
            if(res <= base && ans < res){
                ans = res;
                suger_water = tmp;
                ans_suger = suger[j];
            }
        }
    }
    cout << suger_water << " " << ans_suger << endl;

    return 0;
}

Measured memory_bytes: 512
A,B,C,D,E,F = map(int, input().split())

W = []
S = []
for i in range((F//A)+1):
	j = 0
	while True:
		temp =  100*A*i + 100*B*j
		if temp <= F:
			W.append(temp)
		else:
			break

		j += 1


for i in range((F//C)+1):
	j = 0
	while True:
		temp =  C*i + D*j
		if temp <= F:
			S.append(temp)
		else:
			break

		j += 1

W.pop(0)
S.pop(0)

ans = 0
ans_whole = 0
ans_sugar = 0
for w in W:
	for s in S:
		if w+s <= F and s <= (w/100)*E:
			if ans <= (100*s)/(w+s):
				ans = (100*s)/(w+s)
				ans_whole = w+s
				ans_sugar = s

if ans == 0:
	print(100*A, end = " ")
	print(0)

else:
	print(ans_whole, end= " ")
	print(ans_sugar)
		


		

Measured memory_bytes: 12440
#include <stdio.h>

int main(void)
{

    int x[3000], y[3000];
    int i = 0;
    int j, xd, yd;

    do {
        scanf("%d %d", &xd, &yd);
        x[i] = xd; y[i] = yd;
        i++;
    }while(xd!= 0 || yd!= 0);

    for (j = 0; j < i - 1; j++)
        if (x[j] < y[j])
            printf("%d %d\n", x[j], y[j]);
        else
            printf("%d %d\n", y[j], x[j]);

    return 0;
}

Measured memory_bytes: 624
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vector<string> s(N);
    vi t(N);
    for (int i = 0; i < N; i++)
        cin >> s[i] >> t[i];
    cin >> S;
    bool flag = false;
    for (int i = 0; i < N; i++) {
        if (flag) {
            ans += t[i];
        }
        flag |= s[i] == S;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
long long gcd(long long A, long long B) {
	if (B == 0) return A;
	return gcd(B, A % B);
}
int main() {
	int X;
	scanf("%d", &X);
	printf("%lld", 360 / gcd(X, 360));
	return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int A, B, C, D;
signed main() {
    cin >> A >> B >> C >> D;
    while (true) {
        C -= B;
        if (C <= 0) { fin("Yes"); }
        A -= D;
        if (A <= 0) { fin("No"); }
    }
}

Measured memory_bytes: 3624
import java.util.*;

class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		String s = scan.next();

		HashSet<Character> hash = new HashSet<Character>();
		char c;
		Boolean flag = true;
		if(s.length() % 2 != 0)
			flag = false;
		else{
			for(int i = 0; i < s.length(); i++){
				c = s.charAt(i);
				if(!hash.contains(c))hash.add(c);
				else hash.remove(c);
			}
		}
		if(!flag)System.out.print("No");
		else if(hash.size()==0)System.out.print("Yes");
		else System.out.print("No");
	}

}


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

int main() {

    int n,rc=0,wc=0,i;
    cin >> n;
    string s;
    cin >> s;
    for(i=0;i<n;i++)
    {
        if(s[i]=='R')
            rc++;
    }
    for(i=0;i<rc;i++)
    {
        if(s[i]=='W')
            wc++;
    }
    cout << wc;

}


Measured memory_bytes: 3736