akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

 class Main {

    
    public static void main(String[] args) {
      Scanner in = new Scanner(System.in);
      int n=in.nextInt();
      int m=in.nextInt();
      int[] AC = new int[n];
      int[] WA = new int[n];
      int acount=0;
      int wcount=0;
      
        for (int i = 0; i < m; i++) {
            int s=in.nextInt();
            String v=in.next();
             if(v.equals("WA") && AC[s-1] == 0){
                WA[s-1]++;
            }
            if(v.equals("AC")){
                AC[s-1] = 1;
            }
        }
        
        for(int i = 0; i < n; i++){
            acount += AC[i];
            if(AC[i] == 1){
                wcount += WA[i];
            }
        }
        System.out.println(acount+" "+wcount);
    }
    
    
}

Measured memory_bytes: 64772
n = int(input())

jobs = [None]*n
for i in range(n):
  a, b = map(int, input().split())
  jobs[i] = (b, a)

jobs.sort()

ans = True
sub = 0
for i in range(n):
  b, a = jobs[i][0], jobs[i][1]
  sub += a
  if sub > b:
    ans = False
    break

print("Yes" if ans else "No")

Measured memory_bytes: 29400
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
 
using namespace std;

signed main()
{
    fast;
    int n,a,b;

    cin>>n>>a>>b;

    int x = n/(a+b);
    int d = n - (x*(a+b));

    int sum = 0;

    sum += x*a;
    sum += min(a,d);

    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
List = list(map(int, input().split()))
sumList = [0]*8
mid = 0
for i in range(N):
  if 1<=List[i]<=399:
    sumList[0] += 1
  elif 400<= List[i] <=799:
    sumList[1] += 1
  elif 800 <= List[i] <= 1199:
    sumList[2] += 1
  elif 1200<= List[i] <=1599:
    sumList[3] += 1
  elif 1600<= List[i] <=1999:
    sumList[4] += 1
  elif 2000 <= List[i] <= 2399:
    sumList[5] += 1
  elif 2400 <= List[i] <= 2799:
    sumList[6] += 1
  elif 2800 <= List[i] <= 3199:
    sumList[7] += 1
  elif 3200 <= List[i]:
    mid += 1
res1 = 8 - sumList.count(0)
res2 = res1 + mid
if res1 == 0 and mid > 0:
  res1 = 1
print(res1,res2)

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

using namespace std;

int main(int argc, char *argv[]) {
    int N, M;
    cin >> N >> M;

    map<int, int> m;
    int k, cur;
    for (int i = 0; i < N; i++) {
        cin >> k;
        for (int j = 0; j < k; j++) {
            cin >> cur;
            m[cur] += 1;
        }
    }

    int ans = 0;
    for (auto p: m) {
        if (p.second == N) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

int main()
{
    string W;
    cin >> W;
    int count = 0;
    while(true){
        string s;
        cin >> s;
        if(s == "END_OF_TEXT") break;
        for(int i=0; i<s.size(); i++){
            if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';
        }
        if(s == W) count += 1;
    }
    cout << count << endl;

    /*
    string s = "abcdeabloab";
    int s_ab = s.find("ab");
    string p = "ab";
    while(true){
        int s_ab = s.find(p);
        if(s_ab == string::npos) break;
        cout << s_ab << endl;
        s = s.substr(s_ab + p.size());
    }
    */
}


Measured memory_bytes: 3168
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-07 23:18:04
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int64 n, a, b; cin >> n >> a >> b;
  int64 ab = a + b;
  int64 m = n % ab;
  cout << n / ab * a + min(m, a) << endl;

  return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize(\"Ofast,no-stack-protector\")
//#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx\")
//#pragma GCC target(\"avx,tune=native\")
// Neil

#include<bits/stdc++.h>

using namespace std;

typedef complex<double> base;
typedef long double ld;
typedef long long ll;

#define endl "\n"
#define pb push_back
#define pii pair<int,int>
#define pll pair< ll , ll >
#define vi vector<int>
#define vvi vector< vi >
const int MAXN=(int)(2e5+5);
const ll MOD=(ll)(1e9+7);
int t;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, k, x,y;
    cin>>n>>k>>x>>y;
    cout<<x*min(n,k) + y*max(n-k,0)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unordered_set<int> uset;

int main( int argc, char* argv[] ){
  int N;
  string S;
  cin >> N >> S;
  vector<int> w(N,0), e(N,0);
  int c = 0;
  for( int i=0; i<N; ++i ){
    w[i] = c;
    if( S[i] == 'W' ) c++;
  }
  c = 0;
  for( int i=N-1; i>=0; --i ){
    e[i] = c;
    if( S[i] == 'E' ) c++;
  }
  vector<int> sum(N,0);
  for( int i=0; i<N; ++i ){
    sum[i] = w[i] + e[i];
  }
  auto it = min_element( sum.begin(), sum.end() );
  cout << (*it) << endl;
  return 0;
}


Measured memory_bytes: 4228
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    long d[n];
    for(int i = 0;i<n;i++) cin >> d[i];
    long ans = 0;
    for(int i = 0;i<n-1;i++) for(int j = i+1;j<n;j++) ans+=(d[i]*d[j]);
    cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

s=list(input())

wtotal=s.count("W")
etotal=s.count("E")
wl=[];el=[]
wcount=0
ecount=0
for i in range(n):
    if s[i]=="E":
        ecount+=1
    el.append(ecount)
for i in range(n-1,-1,-1):
    if s[i]=="W":
        wcount+=1
    wl.append(wcount)

wl.reverse()
mn=etotal-el[0]
for i in range(n):
    mn=min(mn,wtotal-wl[i]+etotal-el[i])

print(mn)


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


def arihon_SA(T):
    rank = [0] * (n + 1)
    SA = [0] * (n + 1)
    temp = [0] * (n + 1)

    def rank_calc(i):
        res1 = rank[i]
        res2 = -1
        if i + k <= n:
            res2 = rank[i + k]
        return (res1, res2)

    for i in range(n + 1):
        SA[i] = i
        if i < n:
            rank[i] = ord(T[i])
        else:
            rank[i] = -1
    k = 1

    while k <= n:
        SA.sort(key=rank_calc)
        temp[SA[0]] = 0
        for i in range(1, n + 1):
            temp[SA[i]] = temp[SA[i - 1]]
            if rank_calc(SA[i - 1]) < rank_calc(SA[i]):
                temp[SA[i]] += 1
        rank = temp[::]
        k *= 2

    return SA


# SAとsからSA[i+1],SA[i]の共通接頭辞LCP[i]を求めたい。
# len(s)=nならlen(SA)=n+1
# LCP[0]は必ず0
def arihon_LCP(s, SA):
    num = len(s)
    rank = [0] * (num + 1)
    LCP = [-1] * (num)
    for i in range(num + 1):
        rank[SA[i]] = i
    h = 0
    LCP[0] = 0
    for i in range(num):
        j = SA[rank[i] - 1]
        if h > 0:
            h -= 1
        while j + h < num and i + h < num:
            if s[j + h] != s[i + h]:
                break
            else:
                h += 1
        LCP[rank[i] - 1] = h
    return LCP


SA = arihon_SA(s)
LCP = arihon_LCP(s, SA)

# sparse table
num = n.bit_length()
ST = [[0] * (num + 1) for _ in range(n)]

for i in range(n):
    ST[i][0] = LCP[i]

for j in range(num):
    for i in range(n):
        ST[i][j + 1] = ST[i][j]
        delta = 1 << j
        if i + delta < n:
            ST[i][j + 1] = min(ST[i][j + 1], ST[i + delta][j])


def query(a, b):
    if a > b:
        a, b = b, a
    d = (b - a).bit_length() - 1
    delta = 1 << d
    res = min(ST[a][d], ST[b - delta][d])
    return res


ans = 0
for i in range(n):
    for j in range(i + 1, n + 1):
        a = SA[i]
        b = SA[j]
        temp = query(i, j)
        if abs(b - a) >= temp:
            ans = max(ans, temp)
print(ans)


Measured memory_bytes: 77504
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int dp[2][1<<21];
int bit[501],bit2[25][501],cnt[501];
int main(){
    int n,m;
    string s;
    while(cin>>n>>m,n){
        if(m<=20){
            memset(bit,0,sizeof(bit));
            rep(i,n){
                cin>>s;
                rep(j,m)if(s[j]=='1') bit[i]|=1<<j;
            }
            memset(dp,-1,sizeof(dp));
            dp[0][0]=0;
            rep(i,n){
                rep(j,1<<m) dp[1][j]=dp[0][j];
                rep(j,1<<m)if(dp[0][j]!=-1){
                    dp[1][j^bit[i]]=max(dp[1][j^bit[i]],dp[0][j]+1);
                }
                swap(dp[0],dp[1]);
            }
            cout<<dp[0][0]<<endl;
        }
        else{
            memset(bit2,0,sizeof(bit2));
            rep(i,n){
                cin>>s;
                rep(j,m)if(s[j]=='1') bit2[i][j]=1;
            }
            int mx=0;
            rep(i,1<<n){
                int c=__builtin_popcount(i);
                if(mx>=c) continue;
                memset(cnt,0,sizeof(cnt));
                rep(j,n)if((i>>j)&1)rep(k,m) cnt[k]^=bit2[j][k];
                int sum=0;
                rep(j,m) sum+=cnt[j];
                if(sum==0) mx=max(mx,c);
            }
            cout<<mx<<endl;
        }
    }
    return 0;
}


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

int main(){
    vector<int> a(5);
    int ans = 0;
    for(int i = 0; i < 5; i++){
        int tmp;
        cin >> tmp;
        ans += ((tmp+10-1)/10)*10;
        tmp %= 10;
        a[i] = tmp;
    }
    sort(a.begin(),a.end());
    for(int i = 0; i < 5; i++){
        if(a[i] != 0){
            ans -= 10-a[i];
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ll N, M, Q;
using Tup = tuple<ll, ll, ll, ll>;
vector<Tup> queries;
ll ans = 0;

void dfs(Vl vec) {
    if ((ll)vec.size() == N) {
        ll t = 0;
        for (const auto& [a, b, c, d] : queries) {
            if (vec[b] - vec[a] == c) {
                t += d;
            }
        }
        ans = max(ans, t);
        return;
    }

    for (ll x = vec.back(); x <= M; x++) {
        Vl n_vec = vec;
        n_vec.emplace_back(x);
        dfs(n_vec);
    }
}

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif

    cin >> N >> M >> Q;
    queries.resize(Q);
    for (ll i = 0; i < Q; i++) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        --a, --b;
        queries[i] = make_tuple(a, b, c, d);
    }

    Vl vec{1};
    dfs(vec);

    cout << ans << endl;

    cout << flush;
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define N 1010
#define Q 1000000007
using namespace std;
char s[N][N];
int qp(int a,long long b){
	int r=1;
	b%=Q-1;
	while(b){
		if(b&1) r=1LL*r*a%Q;
		b>>=1;
		a=1LL*a*a%Q;
	}
	return r;
}
int main(){
	int h,w,m=0,lc=0,lp=0;
	int ud=0,lr=0;
	long long k,ans;
	scanf("%d%d%lld",&h,&w,&k);
	for(int i=0;i<h;i++) scanf("%s",s[i]);
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(s[i][j]=='#') m++;
		}
	}
	for(int i=0;i<h;i++) if(s[i][0]=='#'&&s[i][w-1]=='#') lr++;
	for(int i=0;i<w;i++) if(s[0][i]=='#'&&s[h-1][i]=='#') ud++;
	if(lr&&ud||k<2) puts("1");
	else{
		if(lr){
			lp=lr;
			for(int i=0;i<h;i++){
				for(int j=0;j+1<w;j++){
					if(s[i][j]=='#'&&s[i][j+1]=='#') lc++;
				}
			}
		}
		else if(ud){
			lp=ud;
			for(int i=0;i<w;i++){
				for(int j=0;j+1<h;j++){
					if(s[j][i]=='#'&&s[j+1][i]=='#') lc++;
				}
			}
		}
		ans=qp(m,k-1);
		int tmp;
		if(m==lp) tmp=(k-1)%Q*qp(m,k-2)%Q;
		else tmp=1LL*(qp(m,k-1)-qp(lp,k-1))*qp(m-lp,Q-2)%Q;
		if(tmp<0) tmp+=Q;
		ans-=1LL*tmp*lc%Q;
		if(ans<0) ans+=Q;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,h,m;
  cin>>a>>b>>h>>m;
  
  double rad=3.141592653589793/30*m-3.141592653589793/6*h-3.141592653589793/360*m;
  if(rad>3.141592653589793){
    rad=6.283185307179586-rad;
  }
  
  double ans=a*a+b*b-2*a*b*cos(rad);
        cout << fixed << setprecision( 10 ) << sqrt(ans) << endl;
  return 0;
}

Measured memory_bytes: 4228
// created_by  Rishi_Mohan

#include<bits/stdc++.h>

#define    ll           long long
#define    db1(x)       cout<<#x<<"="<<x<<'\n'
#define    db2(x,y)     cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define    db3(x,y,z)   cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define    pi 3.14159265358979323846264338327950L
using namespace std;
//const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286L;
void solve()
{
    int a,b,h,w;
    cin >> a >> b >> h >> w;

   // find angle
   if(h == 12) h=0;
   if(w == 12) w=0;

   // hour moved = 1/2 * (h*60 + m);
   double h_angle = 0.5 * (h * 60 + w);
   // minute moved = 6*m;
   int mm_angle = 6 * w;

   double angle = abs(h_angle - mm_angle);

   // always two angle formed we want smaller
   angle = min(360-angle,angle);
  // cout << angle << endl;
   double ans , temp;

   temp = (angle /  180) * pi;


   ans = double(a*a + b*b - cos(temp)*2.0*a*b );
   cout << setprecision(20) << fixed << sqrt(ans) << endl;




}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}


Measured memory_bytes: 4212
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int main(){
	int w[6] = {2,10,3,12,5,15}, v[6] = {380,380*5*0.8,550,550*4*0.85,850,850*3*0.88};
	int N;
	while(cin>>N,N){
		N /= 100;
		int dp[51]; fill_n(dp,51,INT_MAX/2); dp[0] = 0;
		for(int i=0;i<N;i++){
			for(int j=0;j<6;j++){
				if(i+w[j]<=N) dp[i+w[j]] = min(dp[i+w[j]],dp[i]+v[j]);
			}
		}
		printf("%d\n",dp[N]);
	}
}

Measured memory_bytes: 1144
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

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

  int a,b,t;
  cin >> a >> b >> t;

  int curTime = 0;
  int cur = 1;
  int ans = 0;
  while(curTime+a*cur <= (t+0.5)) {
    ans += b;
    cur++;
  }

  cout << ans << endl;
  return 0;
}


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

int intAbs(int x){
	if(x<0) return x*-1;
	return x;
}

int solve(int pos,int N,int DP[],int stones[],int K=2){
	if(DP[pos]!=INF) return DP[pos];
	int ret=INF;
	if(pos>N) return INF;
	if(N==(pos+1)) return 0; 
	for(int i=1;i<=K;i++){
		if(i+pos<N){
			ret=min(ret,solve(pos+i,N,DP,stones,K)+intAbs(stones[pos+i]-stones[pos]));
//			cout<<pos<<","<<ret<<endl;
		}
	}
	return DP[pos]=ret;
}

int main(){
	int N,K;
	cin>>N>>K;
	int bestValue[N]={};
	int stones[N];
	for(int i=0;i<N;i++){
		cin>>stones[i];
		bestValue[i]=INF;
	}
	cout<<solve(0,N,bestValue,stones,K)<<"\n";
	return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

const int N = 3000 + 5;
vector<lli> a;

lli memo[N][N];
lli rec(int begin, int end, int turn)
{
  unless (begin <= end) return 0;
  lli& ret = memo[begin][end];
  if (ret != -1) return ret;

  const lli inf = 1LL << 60;
  lli best;
  if (turn) {
    best = -inf;
    setmax(best, rec(begin, end - 1, turn ^ 1) + a[end]);
    setmax(best, rec(begin + 1, end, turn ^ 1) + a[begin]);
  } else {
    best = inf;
    setmin(best, rec(begin, end - 1, turn ^ 1) - a[end]);
    setmin(best, rec(begin + 1, end, turn ^ 1) - a[begin]);
  }
  
  return ret = best;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    a.resize(n);
    cin >> a;
    fill(&memo[0][0], &memo[N - 1][N - 1] + 1, -1);
    cout << rec(0, n - 1, 1) << endl;
  }
  
  return 0;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(b >= c){
    cout << "delicious" << endl;
  }
  else if(c-b <= a){
    cout << "safe" << endl;
  }
  else{
    cout << "dangerous" << endl;
  }
}

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

#define MAX_NUM (1000000000 + 7)

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T>& A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

i64 modinv(i64 a, i64 m) {
  i64 b = m, u = 1, v = 0;
  while (b) {
    i64 t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

u64 My_Comb(u64 n, u64 k, i64 m) {
  if (n < k) return 0;
  if (k == 0 || n == k) return 1;
  u64 res = 1;
  k = (n / 2 < k) ? n - k : k;
  for (u64 i = 1; i <= k; ++i)
    res = (((res * (n + 1 - i)) % m) * modinv(i, m)) % m;
  return res;
}

u64 My_Pow(u64 a, u64 n, i64 m) {
  u64 tmp = n, calc = 1;
  while (tmp > 0) {
    if (tmp % 2) {
      tmp--;
      calc *= a;
      calc %= m;
    } else {
      a *= a;
      a %= m;
      tmp /= 2;
    }
  }
  return calc;
}

int main() {
  cout << setprecision(18);
  u32 N;
  cin >> N;
  vector<i64> A(N);
  ArrayInput(A);
  map<i64, u64> CondI, CondJ;
  for (i64 i = 0; i < N; ++i) {
    CondI[A[i] + (i + 1)]++;
    CondJ[(i + 1) - A[i]]++;
  }
  u64 res = 0;
  for (i64 i = 0; i < N; ++i) {
    res += CondJ[A[i] + (i + 1)];
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 39044
#include<stdio.h>
int main(){
long long int sum=0;
  int a[4],j,k,l,min,b[4];
scanf("%d", &k);
  
  for(a[0]=1;a[0]<=k;a[0]++){
    for(a[1]=1;a[1]<=a[0];a[1]++){
      for(a[2]=1;a[2]<=a[1];a[2]++){
      	b[0]=a[0];
      	b[1]=a[1];
      	b[2]=a[2];
      	
        while(1){
            min=b[0];
            l=0;
        	if(min>b[1]){
        		min=b[1];
        		l=1;
        	}
        	if(b[0]%min==0 && b[1]%min==0){
        		break;
        	}
        	else{
        	for(j=0;j<=1;j++){
        		if(j!=l){
        			b[j]=b[j]%min;
        		}
        	}
        		
        	}
        }
        b[1]=min;
      	while(1){
            	min=b[1];
        		l=1;
            	if(min>b[2]){
            		min=b[2];
            		l=2;
            	}
            	if(b[2]%min==0 && b[1]%min==0){
              if(a[0]==a[1]&&a[1]==a[2]){
              sum+=min;
              break;
              }
              if(a[0]!=a[1]&&a[1]==a[2]){
              sum+=3*min;
              break;
              }
              if(a[0]==a[1]&&a[1]!=a[2]){
              sum+=3*min;
              break;
              }
              if(a[0]==a[2]&&a[1]!=a[0]){
              sum+=3*min;
              break;
              }
              if(a[0]!=a[1]&&a[1]!=a[2]&&a[0]!=a[2]){
              sum+=6*min;
              break;
              }
            }
        		else{
        			for(j=1;j<=2;j++){
        				if(j!=l){
        					b[j]=b[j]%min;
        				}
                    }
                }}
        }
      }
    }
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 1732
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define inf 0x7fffffff
#define llinf 0x7fffffffffffffffll
using namespace std;
int main()
{
	int i,j,k,n,m,x,y,a,b;
	scanf("%d%d%d%d",&n,&m,&x,&y);
	scanf("%d",&a);
	for(i=1;i<n;i++)
	{
		scanf("%d",&j);
		a=max(a,j);
	}
	scanf("%d",&b);
	for(i=1;i<m;i++)
	{
		scanf("%d",&j);
		b=min(b,j);
	}
	if(a>=b)
	{
		printf("War");
		return 0;
	}
	if(b<=x||a>=y)
	{
		printf("War");
		return 0;
	}
	printf("No War");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000.0
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef complex<double> P;

int n;
double sx, sy, ex, ey;
double mx[50], my[50], Mx[50], My[50], h[50];

double dot(P a, P b) {
  return (a.real() * b.real() + a.imag() * b.imag());
}

double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}

double f(P a, P b, P c) {
  if ( dot(b-a, c-a) < EPS ) return abs(c-a);
  if ( dot(a-b, c-b) < EPS ) return abs(c-b);
  return abs(cross(b-a, c-a)) / abs(b-a);
}

double fx(double x1, double x2, double y, double z){
	double r = x1, l = x2, mr, ml;
	rep(i,50){
		mr = (r*2+l)/3;
		ml = (r+l*2)/3;
		if(f(P(sx,sy),P(ex,ey),P(mr,y)) < f(P(sx,sy),P(ex,ey),P(ml,y))){
			l = ml;
		} else r = mr;
	}
	double ret = f(P(sx,sy),P(ex,ey),P(r,y));
	return sqrt(ret*ret+z*z);
}

double fy(double x, double y1, double y2, double z){
	double r = y1, l = y2, mr, ml;
	rep(i,50){
		mr = (r*2+l)/3;
		ml = (r+l*2)/3;
		if(f(P(sx,sy),P(ex,ey),P(x,mr)) < f(P(sx,sy),P(ex,ey),P(x,ml))){
			l = ml;
		} else r = mr;
	}
	double ret = f(P(sx,sy),P(ex,ey),P(x,r));
	return sqrt(ret*ret+z*z);
}

void solve(){
	cin >> sx >> sy >> ex >> ey;
	rep(i,n) cin >> mx[i] >> my[i] >> Mx[i] >> My[i] >> h[i];
	rep(i,n){
		if(mx[i]<=sx&&sx<=Mx[i]&&my[i]<=sy&&sy<=My[i]){
			puts("0.000");
			return;
		}
		if(mx[i]<=ex&&ex<=Mx[i]&&my[i]<=ey&&ey<=My[i]){
			puts("0.000");
			return;
		}
	}
	double s = 0.0, e = 10000.0, mid;
	rep(u,50){
		mid = (s+e)/2;
		double dist = INF;
		rep(i,n){
			double z = mid-h[i];
			if(z < 0) z = 0.0;
			dist = min(dist,fx(mx[i],Mx[i],my[i],z));
			dist = min(dist,fx(mx[i],Mx[i],My[i],z));
			dist = min(dist,fy(mx[i],my[i],My[i],z));
			dist = min(dist,fy(Mx[i],my[i],My[i],z));
		}
		if(dist < mid){
			e = mid;
		} else s = mid;
	}
	printf("%.9f\n",s);
}

int main(){
	while(cin >> n){
		if(n == 0) break;
		solve();
	}
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

int main() {
  int p, q, r;
  scanf("%d %d %d", &p, &q, &r);

  int a = p + q;
  a = min(a, p + r);
  a = min(a, q + r);

  cout << a << endl;
}


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

#define ul unsigned long long
#define ll long long

int main()
{
  ul n,x;
  cin>>n>>x;
  ul ct;
  while(n>0||x>0) {
    ct=0;
    for (ul i=1;i<=(n-2);i++) {
      for (ul j=i+1;j<=(n-1);j++) {
        for (ul k=j+1;k<=n;k++) {
          ct+=(i+j+k)==x;
        }
      }
    }
    cout<<ct<<endl;
    cin>>n>>x;
  }


  return 0;
}





Measured memory_bytes: 3048
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N, C;
    cin >> N >> C;

    vector<ll> X(N), V(N);
    REP(i, N) cin >> X[i] >> V[i];

    vll v1(N);
    ll prev = 0;
    REP(i, N) v1[i] += prev + V[i], prev = v1[i];
    REP(i, N) v1[i] -= X[i];

    vll X_rev = X, V_rev = V;
    reverse(ALL(X_rev)); reverse(ALL(V_rev));

    vll v2(N);
    prev = 0;
    REP(i, N) v2[i] += prev + V_rev[i], prev = v2[i];
    REP(i, N) v2[i] -= C - X_rev[i];

    ll ans = max(*max_element(ALL(v1)), *max_element(ALL(v2)));
    ans = max(0LL, ans);
    // f -> b
    multiset<ll> s1;
    REP(i, N) s1.insert(v2[i]);
    int j = N - 1;
    REP(i, N - 1) {
        auto it = s1.find(v2[j--]);
        s1.erase(it);
        ans = max(ans, v1[i] + *s1.rbegin() - X[i]);
    }

    // b -> f
    multiset<ll> s2;
    REP(i, N) s2.insert(v1[i]);
    j = N - 1;
    REP(i, N - 1) {
        auto it = s2.find(v1[j--]);
        s2.erase(it);
        ans = max(ans, v2[i] + *s2.rbegin() - C + X_rev[i]);
    }

    print(ans);
}


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

int main() {
 int n;
    cin >> n;
    vector<int> a(n);
    
  rep(i,n) {
   cin >> a[i];
  }
    
    int count = 0;
    
    for(int i = 0; i< n; i++) {
     int minj = i;
      for(int j = i; j < n; j++){
       if(a[j] < a[minj]){
        minj = j;
       }
    }
       if(a[i] != a[minj]) {
           swap(a[i],a[minj]);
            count++;
                           }
    }
    
    rep(i,n-1){
     cout << a[i] << ' ';
    }
    cout << a[n-1] << endl;
    cout << count<< endl;
    
       
}


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

int c[20][20],n;
int dp[100010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>c[i][j];
		}
	}
	dp[0]=0;
	for(int i=1;i<(1<<n);i++){
		vector<int> v;
		for(int j=1;j<=n;j++) if(i&(1<<(n-j))) v.push_back(j);
		for(int j=0;j<v.size();j++){
			for(int k=j+1;k<v.size();k++){
				dp[i]+=c[v[j]][v[k]];
			} 
		}
	}
	for(int i=1;i<(1<<n);i++){
		for(int j=i;j>0;j=(j-1)&i){
			dp[i]=max(dp[i],dp[j]+dp[i^j]);
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
using namespace std;
#define f(i,n) for(int i=1;i<=n;i++)

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

int main(){
	int n;
	cin>>n;
	long long ans = 0;
	f(i,n){
		f(j,n){
			f(k,n){
				ans+=gcd(i,gcd(j,k));
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
using namespace std;
int main() {
  int a, b , d , r;
  double f;
  cin >> a >> b;
  d = a / b;
  r = a % b;
  f = (double)a/(double)b;
  printf("%d %d %f\n" , d , r , f);
  return 0;
}


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

string a,b;
int memo[3005][3005];

int dp(int id1, int id2){
   if(id1>=a.size() || id2>=b.size()) return 0;
   int &ret = memo[id1][id2];
   if(ret!=-1) return ret;
   if(a[id1] == b[id2]) ret = dp(id1+1,id2+1)+1;
   else ret = max(dp(id1+1,id2) , dp(id1,id2+1));
   return ret;
}

void bt(int id1, int id2){
   if(id1>=a.size() || id2>=b.size()) return ;
   if(a[id1] == b[id2]){
      cout << a[id1];
      bt(id1+1,id2+1);
   } else{
      if(dp(id1+1,id2) > dp(id1,id2+1)) bt(id1+1,id2);
      else bt(id1,id2+1);
   }
   return ;
}

int main(){
   cin >> a >> b;
   memset(memo,-1,sizeof(memo));
   int ans = dp(0,0);
   bt(0,0);
   cout << endl;
	return 0;
}


Measured memory_bytes: 35840
#include <stdio.h>

int main(void)
{
	int chukan[1000],kimatu[1000],tuishi[1000];
	int i;
	int qty;
	int sum;
	
	for(i=0;i<1000;i++)
	{
		scanf("%d %d %d",&chukan[i],&kimatu[i],&tuishi[i]);
		
		if((chukan[i] == -1) && (kimatu[i] == -1) && (tuishi[i] == -1))
		{
			qty = i;
			
			goto next;
		}
	}
	
	next:
	
	for(i=0;i<qty;i++)
	{
		sum = chukan[i] + kimatu[i];
		
		if(chukan[i] == -1 || kimatu[i] == -1)
		{
			printf("F");
		}
		else if(sum >= 80)
		{
			printf("A");
		}
		else if(sum >= 65 && sum < 80)
		{
			printf("B");
		}
		else if(sum >= 50 && sum < 65)
		{
			printf("C");
		}
		else if(sum >= 30 && sum < 50)
		{
			if(tuishi[i] >= 50)
			{
				printf("C");
			}
			else
			{
				printf("D");
			}
		}
		else if(sum < 30)
		{
			printf("F");
		}
		
		printf("\n");
		
	}
	
	return 0;
}

Measured memory_bytes: 1744
// 簡易競プロテンプレ
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main(void){
 cin >> n >> s;
 int ans = 0, now = 0;
 for(int i=0;i<n;i++) {now += ((s[i]=='I') ? 1 : -1); ans = max(ans, now);}
 cout << ans << endl;
 return 0;
}

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

int main(){
    int N, K, H[100000];
    cin >> N >> K;
    for(int i=0; i<N; i++) cin >> H[i];

    vector<int> dp(N, 2e9);
    dp[0] = 0;
    for(int i=1; i<N; i++) for(int j=max(0, i-K); j<i; j++) dp[i] = min(dp[i], dp[j] + abs(H[i] - H[j]));
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
// #include <stdlib.h>
long long solve(long long, long long);
long long pow2(long long);
long long a[5] = {0, 1, 2, 3, 3};
int main()
{
  long long n, x;
  scanf("%lld%lld", &n, &x);
    long long ans;
  ans = solve(n, x);
  printf("%lld\n",ans);
  return 0;
}
long long solve(long long n, long long x)
{
  if(x==0) return 0;
  if (n==1)
  {
    return a[x-1];
  }
  long long st = pow2(n+1) - 1, ans;//每行面包 肉饼个数和 的一半 包括中间的
  if (n>1)
  {
    if (x >= st){
      // printf("st = %lld\n", st);
      // printf("n-1 = %lld x-st = %lld solve(n-1, x-st) = %lld\n", n-1, x-st, solve(n-1, x-st-1));
      // printf("pow2(n) = %lld\n", pow2(n));
      if (x-st < pow2(n+1)-2)
        ans = pow2(n)-1 + 1 + solve(n-1, x-st);//2 13
      else
        ans = pow2(n)-1 + 1 + solve(n-1, x-st-1);//2 13
      // printf("ans = %lld\n", ans);
    }
    else{
      ans = solve(n-1, x-1);
    }
  }
  return ans;
}
long long pow2(long long n)
{
  long long x = 1;
  for (int i = 0; i < n; ++i)
    x *= 2;
  return x;
}


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

int main(){
  int A,B;
  vector<int> vec(999);
  cin>>A>>B;
  vec.at(0)=1;
  for(int i=1;i<999;i++)
    vec.at(i)+=vec.at(i-1)+(i+1);

  int sa = B-A;
  
  cout<<vec.at(sa-1)-B<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        // int n = Integer.parseInt(bf.readLine());
        StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        int count = 0;
        for(int i=11; i<=d; i++) {
          if((i%10)*(i/10) <= m)
            if((i%10)*(i/10) >= 1)
              if(i%10 >= 2)
                if(i/10 >= 2)
                  count++;
        }
        out.println(count);

        out.close(); System.exit(0);
    }
}


Measured memory_bytes: 22484
import numpy as np
if __name__ == "__main__":
    K, S = list(map(int, input().split()))
    ans = 0
    for i in range(K+1):
        for j in range(i, K+1):
            k = S - (i+j)
            if j <= k and k <= K:
                l = len(set([i,j,k]))
                if l == 3:
                    ans += 6
                elif l == 2:
                    ans += 3
                else:
                    ans += 1
    print(ans)

Measured memory_bytes: 21152
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const int imax = ~(1 << 31);
const long long linf = 1ll << 61;
const long long lmax = ~(1ll << 63);

#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))

int H, W;
char S[12][20];

bool check(char T[12][20], int h, int w)
{
	bool P[12] = {};
	int count = 0;
	for (int i = 0; i < w; i++) {
		for (int j = i + 1; j < w; j++) {
			if (P[i] || P[j]) continue;
			bool f = true;
			for (int k = 0; k < h; k++) {
				if (T[k][i] != T[h - k - 1][j]) {
					f = false;
					break;
				}
			}
			if (f) {
				P[i] = true;
				P[j] = true;
				count += 2;
			}
		}
	}
	if (count == w) return true;
	if (count <= w - 2) return false;
	for (int i = 0; i < w; i++) {
		if (P[i]) continue;
		for (int k = 0; k < h; k++) {
			if (T[k][i] != T[h - k - 1][i]) {
				return false;
			}
		}
		return true;
	}
	return false;
}

bool next_group(int* A, int n)
{
	bool used[12];
	fill(used, used + n, true);
	for (int i = n / 2 - 1; i >= 0; i--) {
		int first = A[i * 2];
		int second = A[i * 2 + 1];
		used[second] = false;
		bool overflow = true;
		for (int j = second + 1; j < n; j++) {
			if (!used[j]) {
				second = j;
				overflow = false;
				break;
			}
		}
		if (!overflow) {
			A[i * 2 + 1] = second;
			used[second] = true;
			int k = (i + 1) * 2;
			for (int j = 0; j < n; j++) {
				if (used[j]) continue;
				A[k] = j;
				used[j] = true;
				k++;
			}
			return true;
		}
		used[first] = false;
	}
	return false;
}

int main(int argc, char* argv[])
{
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; i++) {
		scanf("%s", S[i]);
	}
	int P[12];
	int K = H + (H & 1);
	for (int i = 0; i < K; i++) {
		P[i] = i;
	}
	char T[12][20];
	do {
		for (int i = 0; i < K; i++) {
			if (P[i] == H) {
				int p = P[i & 1 ? i - 1 : i + 1];
				for (int j = 0; j < W; j++) {
					T[H / 2][j] = S[p][j];
				}
				break;
			}
		}
		int y = 0;
		for (int i = 0; i < K; i += 2) {
			if (P[i] == H || P[i + 1] == H) continue;
			for (int j = 0; j < W; j++) {
				T[y][j] = S[P[i]][j];
				T[H - y - 1][j] = S[P[i + 1]][j];
			}
			y++;
		}
		if (check(T, H, W)) {
			printf("YES\n");
			return 0;
		}
	} while (next_group(P, K));
	printf("NO\n");

	return 0;
}


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

using namespace std;

char S[4001];
int cnt[4001][3];

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

	int n;

	cin >> n;

	for(int i=1;i<=n;i++)
	{
		cin >> S[i];
		for(int j=0;j<3;j++)
		{
			cnt[i][j] += cnt[i-1][j];
		}
		if(S[i]=='R')
		{
			cnt[i][0] += 1;
		}
		else if(S[i]=='G')
		{
			cnt[i][1] += 1;
		}
		else
		{
			cnt[i][2] += 1;
		}
	}

	long long int res = 0;

	for(int j=1;j<=n;j++)
	{
		for(int k=j+1;k<=n;k++)
		{
			if((S[j]=='R' && S[k]=='G') || (S[j]=='G' && S[k]=='R'))
			{
				int x = cnt[j-1][2];
				int d = k-j;
				if(j-d>=1)
				{
					if(S[j-d]=='B')
					{
						x--;
					}
				}
				res += x;
			}
			else if((S[j]=='R' && S[k]=='B') || (S[j]=='B' && S[k]=='R'))
			{
				int x = cnt[j-1][1];
				int d = k-j;
				if(j-d>=1)
				{
					if(S[j-d]=='G')
					{
						x--;
					}
				}
				res += x;
			}
			else if((S[j]=='G' && S[k]=='B') || (S[j]=='B' && S[k]=='G'))
			{
				int x = cnt[j-1][0];
				int d = k-j;
				if(j-d>=1)
				{
					if(S[j-d]=='R')
					{
						x--;
					}
				}
				res += x;				
			}
		}
	}

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main(void){
  
    int n,m;
    
    cin >> n >> m;
 
    int left=1, right=n;
        
    for(int i=0; i < m; i++){
        int a,b;
        cin >> a >> b;
        if(a > left)left=a;
        if(b < right)right=b;
    }
    if(right < left)cout << 0 << endl;
    else cout << right-left+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m;
char a[509][509],b[509][509],c[509][509];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
			c[i][j]=b[i][j]=a[i][j];
		}
	for(int i=1;i<=n;i+=2)
		for(int j=2;j<m;j++)	b[i][j]='#';
	for(int i=1;i<=n;i++)	b[i][1]='#';
	for(int i=2;i<=n;i+=2)
		for(int j=2;j<m;j++)	c[i][j]='#';
	for(int i=1;i<=n;i++)	c[i][m]='#';
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
			printf("%c",b[i][j]);
		printf("\n");
	}
	printf("\n");
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
			printf("%c",c[i][j]);
		printf("\n");
	}
	return 0;
} 

Measured memory_bytes: 1536
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(void){
  //long table[11][101][1001];
  long **table[11];
  for(int i=0;i<=10;i++){
    table[i]=(long **)malloc(101*(sizeof(long *)));
    for(int j=0;j<=100;j++){
      table[i][j]=(long *)malloc(1001*sizeof(long));
    }
  }
  for(int i=0;i<=10;i++){
    for(int j=0;j<=100;j++){
      for(int s=0;s<=1000;s++){
        table[i][j][s]=0;
      }
    }
  }

  for(int j=0;j<=100;j++){
    table[1][j][j]=1;
  }

  for(int i=2;i<=10;i++){
    for(int j=0;j<=100;j++){
      for(int s=0;s<=1000;s++){
        if(s>=j){
        for(int k=0;k<j;k++){
            table[i][j][s]+=table[i-1][k][s-j];
          }
        }
      }
    }
  }

  int n,s;
  while(true){
    cin>>n>>s;
    if(n==0 and s==0){break;}
    long retval=0;
    for(int j=0;j<=100;j++){
      retval+=table[n][j][s];
    }
    cout<<retval<<endl;
  }
  return 0;
}



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

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

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

int main(void){
    vector<pair<int, int>> ans;
    // ((対角線, 高さ), 横)
    vector<pair<pair<int, int>, int>> rect;
    for(int i = 1; i <= 150; i++){
        for(int j = i+1; j <= 150; j++){
            //横がj
            rect.push_back(make_pair(make_pair(i*i + j*j, i), j));
        }
    }
    sort(rect.begin(), rect.end());
    while(true){
        int h, w; cin >> h >> w;
        if(h == 0 && w == 0) break;
        pair<int, int> key = make_pair(h*h + w*w, h);
        int res = 0;
        while(key >= rect[res].first) res++;
        ans.push_back(make_pair(rect[res].first.second, rect[res].second));
    }
    rep(i, ans.size()) cout << ans[i].first << " " << ans[i].second << endl;
    return 0;
}


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

typedef long long ll;

int n;

int dig_sum(int a){
    int sum = 0;
    while (a > 0){
        sum += a % 10;
        a /= 10;
    }
    return sum;
}

int main(){
    cin >> n;
    int min_s = 123456789;
    for (int i = 1; i <= n/2; i++){
        int a = i;
        int b = n-i;
        min_s = min(min_s, dig_sum(a)+dig_sum(b));
    }
    cout << min_s << endl;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b; char op;
    while(cin>>a>>op>>b, op!='?'){
        switch(op){
            case '+':
                cout<<a+b;
                break;
            case '-':
                cout<<a-b;
                break;
            case '*':
                cout<<a*b;
                break;
            case '/':
                cout<<a/b;
        }
        cout<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3212
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
                int a = sc.nextInt();
                int b = sc.nextInt();

		List<String> list = new ArrayList<String>();


		for(int i = 0; i < b; i++){
			list.add(sc.next());
		}

                int f = 0;


           	for(int i = 0; f < 1; i++){
		  for(int j = 0; j < list.size(); j++){
		  	if(String.valueOf(a + i).contains(list.get(j))){
			  break;
			}else if(j == list.size() - 1){
			  System.out.println(a + i);
			  f = 1;
			}
		  }
		}
     }
}              

Measured memory_bytes: 31160
// https://atcoder.jp/contests/abc084/tasks/abc084_d

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))

int dp[100001];
// constexprな素数列挙(エラトステネスの篩)
template <int N> struct calc_prime {
    bool b[N + 1];

    constexpr calc_prime() : b() {
        for (int_fast64_t i = 0; i <= N; ++i)
            b[i] = true;
        b[0] = b[1] = false;
        for (int_fast64_t i = 2; i <= N; ++i) {
            for (int_fast64_t j = i * i; j <= N; j += i)
                b[j] = false;
        }
    }
};
calc_prime<200000> prime;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> l(n), r(n);
    REP(i, n) cin >> l[i] >> r[i];
    for (int i = 1; i <= 100000; i++) {
        dp[i] = dp[i - 1] + (prime.b[i] & prime.b[(i + 1) / 2]);
    }

    for (int i = 0; i < n; i++) {
        cout << dp[r[i]] - dp[l[i] - 1] << "\n";
    }

    return 0;
}

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

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var n = ReadLineIntSpilit();
            var result = "Yes";

            if(n[0] != n[1] && n[1] != n[2] && n[0] != n[2]) {
                result = "No";
            }else if(n[0] == n[1] && n[1] == n[2] && n[0] == n[2]) {
                result = "No";
            }

            Console.WriteLine(result);
            ReadLine();
        }

        /// <summary>
        /// コンビネーション
        /// </summary>
        /// <param name="n"></param>
        /// <param name="m"></param>
        /// <returns></returns>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        /// <summary>
        /// stringを一文字ずつintにキャストして配列に変換します。
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int[] StringCharArrayIntArray(string str)
        {
            List<int> b = new List<int>();
            for (int i = 0; i < str.Length; i++) {
                b.Add( int.Parse(str[i].ToString()));
            }
            return b.ToArray();
        }

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

        public static int ReadLineInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static string[] ReadLineStringSplit(char a = ' ')
        {
            return ReadLine().Split(a).ToArray();
        }

        public static int[] ReadLineIntSpilit(char a = ' ')
        {
            return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        }
    }
}

Measured memory_bytes: 13268