akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int p, a[100];

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> p;
    int cnt = 0;
    for (int i = 1; i <= p; i++) {
        cin >> a[i];
        if (a[i] != i) cnt++;
    }
    if (cnt == 2 || cnt == 0) {
        cout << "YES" << E;
    }
    else {
        cout << "NO" << E;
    }
    //system("pause");
    return 0;
}

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

namespace multiset
{

class multiset
{
  private:
    std::vector<int> tree;
    int MSB;

    void add(int i, int x)
    {
        for (; i < tree.size(); i += i & -i) {
            tree[i] += x;
        }
    }

    int sum(int i)
    {
        int res = 0;
        for (; i > 0; i -= i & -i) {
            res += tree[i];
        }
        return res;
    }

    int bisect(int w)
    {
        int i = 0;
        for (int k = MSB; k > 0; k /= 2) {
            if (i + k < tree.size() && tree[i + k] < w) {
                w -= tree[i + k];
                i += k;
            }
        }
        return i + 1;
    }

    uint32_t get_MSB(uint32_t x)
    {
        return 0x80000000 >> __builtin_clz(x);
    }

  public:
    multiset(int N) : tree(N + 1), MSB(get_MSB(N)) {}
    void insert(int x) { add(x, 1); }
    void erase(int x) { add(x, -1); }
    int lower_bound(int x)
    {
        int s = sum(x);
        return (s == 0) ? 0 : bisect(s);
    }

    size_t size() { return sum(tree.size() - 1); }
};

} // namespace multiset

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

    int N;
    std::cin >> N;

    std::vector<int> A(N);
    for (auto &&a : A) {
        std::cin >> a;
    }

    std::vector<int> B = A;
    std::sort(begin(B), end(B));
    B.erase(std::unique(begin(B), end(B)), end(B));

    std::transform(begin(A), end(A), begin(A), [&](int val) -> int {
        return std::lower_bound(begin(B), end(B), val) - begin(B) + 1;
    });

    multiset::multiset ms(B.size());
    for (auto a : A) {
        auto i = ms.lower_bound(a - 1);
        if (i != 0) {
            ms.erase(i);
        }
        ms.insert(a);
    }

    std::cout << ms.size() << '\n';
}


Measured memory_bytes: 1408
#include <iostream>
#include<string>
#include<algorithm>
#include<iomanip>
#include<stdlib.h>
#include<vector>



using namespace std;

int main() {
	int a, b,c;
	cin >> a>> b>>c;
	
	if (a < b&&b <c) cout << "Yes"<<endl;
	else cout << "No"<<endl;
	
}


Measured memory_bytes: 3096
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static String[] num = {"3", "5", "7"};
	static List<String> list = new ArrayList<String>();
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		sc.close();
		rec("");
		List<Long> list1 = new ArrayList<Long>();
		for(String t : list) {
			if(isCheck(t)) {
				list1.add(Long.parseLong(t));
			}
			//System.out.println(t);
		}
		int cnt = 0;
		//System.out.println(list1.size());
		for(long t : list1) {
			if(t <= N) {
				cnt++;
				//System.out.println(t);
			}
			//System.out.println(t);
		}
		System.out.println(cnt);
	}
	static boolean isCheck(String t) {
		boolean flag1 = false;
		boolean flag2 = false;
		boolean flag3 = false;
		for(int i = 0; i < t.length(); i++) {
			char c = t.charAt(i);
			if(c == '3') {
				flag1 = true;
			}
			if(c == '5') {
				flag2 = true;
			}
			if(c == '7') {
				flag3 = true;
			}
			if(flag1 && flag2 && flag3) {
				return true;
			}
		}
		return false;
	}
	static void rec(String s) {
		if(s.length() > 9) {
			return;
		}
		for(int i = 0; i < 3; i++) {
			//s += num[i];
			list.add(s + num[i]);
			rec(s + num[i]);
			//System.out.println(s);
		}
	}
}

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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int N;
    int h[101];
    int ans = 0;

    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> h[i];
    }


    for(int ch = 0; ch <= 100; ch++) {
        bool b = false;
        for(int n = 1; n <= N; n++) {
            if(!b && h[n] > ch) {
                IFD cout << n << ", " << h[n] << endl;
                b = true;
            } else if(b && h[n] <= ch) {
                IFD cout << "d: " << n << ", " << h[n] << endl;
                ans++;
                b = false;
            }
        }
        if(b) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int N, satisfaction = 0;
    cin >> N;

    vector<int> A(N), B(N),C(N-1);
	
	for (int i = 0; i < N; i++) cin >> A.at(i);
	for (int i = 0; i < N; i++){cin >> B.at(i); satisfaction += B.at(i);}
	for (int i = 0; i < N - 1; i++)cin >> C.at(i);

	for (int i = 1; i < N; i++)
		if (A.at(i) - 1 == A.at(i - 1)) satisfaction += C.at(A.at(i) - 2);
    cout << satisfaction << endl;
    return 0;
}

Measured memory_bytes: 256
import collections

n = int(input())
a = [int(i) for i in input().split(' ')]
c = collections.Counter(a)
counts = {}
all_sum = 0
for k, v in c.items():
    val = v * (v-1) / 2
    counts[k] = val
    all_sum += val

for i in range(n):
    k = a[i]
    count = c[k] - 1
    val = counts[k]
    print(int(all_sum - val + count * (count - 1) / 2))


Measured memory_bytes: 31752
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
map<string, int> mp;
int n;
struct S{
    string s; int cnt;
    friend bool operator < (const S &a, const S &b) {
        if (a.cnt == b.cnt) return a.s < b.s;
        return a.cnt > b.cnt;
    }
};
vector<S> vec;
int main() {
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        string s; cin >> s;
        if (!mp.count(s)) mp[s] = 1;
        else ++mp[s];
    }
    for (auto &pr: mp) {
        vec.push_back({pr.first, pr.second});
    }
    sort(vec.begin(), vec.end());
    for (int i = 0; i < vec.size(); ++i) {
        if (vec[i].cnt != vec[0].cnt) break;
        cout << vec[i].s << endl;
    }
    return 0;
}


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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int b = 0, w = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '.') w++;
        else            b++;
    }
    if(w == 0 || b == 0){
        cout << 0 << endl;
        return 0;
    }
    int ans = min(b,w), wtmp = 0, btmp = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '.'){
            wtmp++; w--;
        }else{
            btmp++; b--;
        }
        ans = min(ans, btmp+w);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

const int MAX_V = 2e5;
vector<int> es[MAX_V];
ll subtree_size[MAX_V], size2[MAX_V];
int top[MAX_V], pre[MAX_V], c[MAX_V], p[MAX_V];

int dfs(int now, int par){
    p[now] = par;
    int size = 1;
    if(top[c[now]] == -1) pre[now] = -1;
    else pre[now] = top[c[now]];
    int memo = top[c[now]];
    for(auto &e: es[now]){
        if(e == par) continue;
        top[c[now]] = e;
        size += dfs(e, now);
    }
    top[c[now]] = memo;
    if(memo == -1) size2[c[now]] -= size;
    subtree_size[now] = size;
    return size;
}

int main(){
    ll N; cin >> N;
    rep(i, N) cin >> c[i], c[i]--;
    rep(i, N-1){
        int a, b; cin >> a >> b; a--, b--;
        es[a].pb(b), es[b].pb(a);
    }
    fill(top, top+N, -1);
    fill(size2, size2+N, N);
    dfs(0, -1);
    //rep(i, N) cout << p[i] << ' ' << pre[i] << ' ' << subtree_size[i] << endl;
    ll ans[N];
    fill(ans, ans+N, N*(N+1)/2);
    ll s[N];
    rep(i, N){
        s[i] = subtree_size[i];
        ans[i] -= size2[i]*(size2[i]+1)/2;
        //cout << size2[i] << endl;
    }
    rep(i, N){
        if(pre[i] == -1) continue;
        s[pre[i]] -= subtree_size[i];
    }
    rep(i, N){
        for(auto &e: es[i]){
            if(e == p[i]) continue;
            ans[c[i]] -= s[e]*(s[e]+1)/2;
        }
    }
    rep(i, N) cout << ans[i] << endl;
}

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

using namespace std;
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
const int N=505,MOD=1e9+7,MAX=1e5;

int n,m,q;

int pref[N][N],a[N][N];

void pre(){

   for(int i=1;i<=n;i++){

     for(int j=1;j<=n;j++){

         pref[i][j]+=pref[i][j-1]+pref[i-1][j]-pref[i-1][j-1];
     }
   }
}

int que(int l,int r){

     return (pref[r][r]-pref[l-1][r]);
}
int main()
{
      
      
       scanf("%d %d %d",&n,&m,&q);

       for(int i=0;i<m;i++){

         int l,r;

         scanf("%d %d",&l,&r);
         
         pref[l][r]++;
         a[l][r]++;
       }

       pre();

       
       while(q--){
        
          int l,r;

          scanf("%d %d",&l,&r);

          printf("%d\n",que(l,r) );

       }  
        
       
 return 0;
}

Measured memory_bytes: 2944
def ABC064D():
    N = int(input())
    S = list(input())
    cnt = 0
    start = 0
    for i in S:
        if i == "(":
            cnt += 1
        elif i == ")":
            cnt -= 1
        if cnt < 0:
            start += 1
            cnt += 1
    tmp = []
    for i in range(start):
        tmp.append("(")
    S = tmp + S
    cnt_start = 0
    cnt_end = 0
    for i in S:
        if i == "(":
            cnt_start += 1
        elif i == ")":
            cnt_end += 1
    tmp = []
    for i in range(cnt_start - cnt_end):
        tmp.append(")")
    S = S + tmp

    for i in S:
        print(i, end = "")
    print()
ABC064D()

Measured memory_bytes: 3064
# coding=utf-8
 
###
### for atcorder program
###
 
import sys
import math
 
# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338
 
    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []
 
        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist
 
    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)
 
    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)
 
    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans
 
mymath = mymath()
 
### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()
 
output = output()
 
### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]
 
#R = float(input())
#A.append(list(map(int,input().split())))
 
#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]
 
#abc list
#abc = [chr(ord('a') + i) for i in range(26)]
 
### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")  

def get_input():
  N = []
  while True:
    try:
      N.append(input())
      #N.append(int(input()))
    except EOFError:
      break
  return N

N = get_input()

for row in N:
  a, b = [int(x) for x in row.split()]
  print(a+b)



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

const int SIZE = 101;
char result[SIZE][SIZE];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= SIZE / 2; i++) {
        for (int j = 1; j < SIZE; j++) {
            result[i][j] = '.';
        }
    }
    for (int i = SIZE / 2 + 1; i < SIZE; i++) {
        for (int j = 1; j < SIZE; j++) {
            result[i][j] = '#';
        }
    }
    for (int i = 1; i < m; i++) {
        int r = i / 98 * 4, c = i % 98;
        if (c == 0) {
            c += 98;
            r -= 4;
        }
        if (c % 2 == 0) {
            r += 2;
        } else {
            r += 3;
        }
        result[r][c + 1] = '#';
    }
    for (int i = 1; i < n; i++) {
        int r = i / 98 * 4, c = i % 98;
        if (c == 0) {
            c += 98;
            r -= 4;
        }
        if (c % 2 == 0) {
            r += 2;
        } else {
            r += 3;
        }
        result[SIZE - r][c + 1] = '.';
    }
    cout << SIZE - 1 << ' ' << SIZE - 1 << '\n';
    for (int i = 1; i < SIZE; i++) {
        for (int j = 1; j < SIZE; j++) {
            cout << result[i][j];
        }
        cout << '\n';
    }
    return 0;
}

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

int main(){
  int N, P, count = 0, ans = 0;
  int A[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
              1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51} ;
  cin >> N ;
  
  cout << A[N-1] << endl ;
  return 0 ;
}

Measured memory_bytes: 256
import sys
import bisect
input = sys.stdin.readline
 
 
def readstr():
    return input().strip()
 
 
def readint():
    return int(input())
 
 
def readnums():
    return map(int, input().split())
 
 
def readstrs():
    return input().split()
 
 
def main():
    N = readint()
    X = list(readnums())
    xs = sorted(X)
    for i in X:
        d = bisect.bisect_left(xs, i)
        if d >= N // 2:
            print(xs[N // 2 - 1])
        else:
            print(xs[N // 2])
 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 88020
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] L = new long[100];
        L[0] = 2;
        L[1] = 1;
        for (int i = 2 ; i <= N ; i++) {
            L[i] = L[i - 1] + L[i - 2];
        }
        System.out.println(L[N]);
    }

}

Measured memory_bytes: 22740
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;

int mind(int e){
  int mind=e;
  for(int i=0;i*i*i<=e;i++){
    for(int j=0;j*j<=e-i*i*i;j++){
      mind=min(i+j+(e-i*i*i-j*j),mind);
    }
  }
  return mind;
}


int main(){
  int E;
  vector<int> a;
  while(cin>>E && E>0){
    a.push_back(mind(E));
  }
  for(int i=0;i<a.size();i++)
    cout<<a[i]<<endl;
}



Measured memory_bytes: 3156
#include <stdio.h>
#define KUBUN 7
int main(void){
  int n,i,j,a,years[KUBUN];
  scanf("%d",&n);
  while(n){
    for(i=0;i<KUBUN;i++)
      years[i]=0;
    for(i=0;i<n;i++){
      scanf("%d",&a);
      for(j=0;j<KUBUN;j++)
	if(a/10==j){
	  years[j]++;break;}
      if(j==KUBUN)
	years[6]++;
    }
    for(i=0;i<KUBUN;i++)
      printf("%d\n",years[i]);
    scanf("%d",&n);
  }
  return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"

#if debug
#include "printer.hpp"
#define dump(a) cerr << #a << "(" << __LINE__ << ") = " << a << endl;
#else
#define dump(...)
#endif

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a, b) for (int i = (b)-1; i >= a; i--)
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
const ll mod = 1000000007;

ll pow(ll x, ll y) {
  ll ret = 1, tmp = x;
  while (y) {
    if (y % 2) ret = ret * tmp % mod;
    tmp = tmp * tmp % mod;
    y /= 2;
  }
  return ret;
}

ll inverse(ll x) { return pow(x, mod - 2); }


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

  vi factorials(N + 1);
  factorials[0] = 1;
  rep(i, 1, N + 1) {
    factorials[i] = factorials[i - 1] * i % mod;
  }
  auto combination = [&](ll x, ll y) {
    ll ans = factorials[x];
    ans = ans * inverse(factorials[y]) % mod;
    ans = ans * inverse(factorials[x - y]) % mod;
    return ans;
  };

  vi A(N);
  rep(i, 0, N) cin >> A[i];
  unordered_map<ll, ll> cnt;
  rep(i, 0, N) {
    cnt[A[i]]++;
  }
  vector<pii> v;
  for (auto p : cnt) v.push_back(p);
  sort(all(v));
  ll m = v.size();
  vi a(m), b(m);
  a[0] = v[0].second;
  rep(i, 1, m) a[i] = a[i - 1] + v[i].second;
  b[m - 1] = v[m - 1].second;
  repr(i, 0, m - 1) b[i] = b[i + 1] + v[i].second;
  ll ans = 0;
  rep(i, 0, m) {
    if (b[i] >= K) {
      if (i + 1 < m && b[i + 1] >= K)
        ans -= v[i].first * (mod + combination(b[i], K) - combination(b[i + 1], K)) % mod;
      else 
        ans -= v[i].first * combination(b[i], K) % mod;
    }
    if (a[i] >= K) {
      if (i - 1 >= 0 && a[i - 1] >= K)
        ans += v[i].first * (mod + combination(a[i], K) - combination(a[i - 1], K)) % mod;
      else 
        ans += v[i].first * combination(a[i], K) % mod;
    }
    ans = (ans % mod + mod) % mod;
  }
  cout << ans << endl;
}


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

int n, m;
int cost[1010];
vector<int>g[1010];
int dp[1<<12];

int f(int vis){
     if(vis==0) return 0;

     int&ans=dp[vis];
     if(ans!=-1) return ans;

     ans=1e9;
     for(int i=0;i<m;i++){
          int val=cost[i];
          int nvis=vis;
          for(int j=0;j<g[i].size();j++){
               int c=g[i][j];
               if((nvis>>c)&1)nvis=nvis^(1<<c);
          }
          ans=min(ans, val+f(nvis));
     }
     return ans;
}

int main(){
     memset(dp, -1, sizeof(dp));
     
     cin>>n>>m;
     for(int i=0;i<m;i++){
          int a, b;
          cin>>a>>b;
          cost[i]=a;
          for(int j=0;j<b;j++){
               int temp;
               cin>>temp;
               temp--;
               g[i].push_back(temp);
          }
     }
    
     int vis=1<<n;
     vis=vis-1;
    int ans=f(vis);
    if(ans==1e9) cout<<-1;
    else cout<<ans;
}

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

int main() {
    int n;
    cin >> n;
    string taro, hanako;

    int ctaro=0;
    int chanako=0;
    
    for(int i = 0; i < n; i++) {
        cin >> taro >> hanako;

        int minimum = max(taro.size(), hanako.size());

        if(taro==hanako) {
            ctaro += 1;
            chanako += 1;
          	//cout << "draw" << i << endl;
        }

        else{
            for(int j = 0; j < minimum; j++) {
                bool draw = false;
                bool taro_win = true;
                bool flag = false;

                if(taro[j] == hanako[j]) draw = true;
                else if(taro[j] < hanako[j]) taro_win = false;

                if(draw == false) {
                    if(taro_win == true) {
                        ctaro += 3;
                   //   	cout << "taro" << i << endl;
                     	break;
                    }
                    else {
                        chanako += 3;
                      //	cout << "hanako" << i << endl;
                      	break;
                    }
                }
             
            }
        }
    }

    cout << ctaro << ' ' << chanako << endl;
}


Measured memory_bytes: 3168
#define _USE_MATH_DEFINES
 
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
 
using namespace std;
 
typedef pair<long long int, long long int> P;
long long int INF = 1e18;

string s;
bool flag = true;

int dfs(int i){
	if(s[i] != 'm'){
		return -1;
	}
	++i;
	if(s[i] == 'm'){
		int next = dfs(i);
		if(next == -1){
			return -1;
		}
		i = next;
	}
	if(s[i] == 'e'){
		++i;
	}else{
		return -1;
	}
	if(s[i] == 'm'){
		int next = dfs(i);
		if(next == -1){
			return -1;
		}
		i = next;
	}
	if(s[i] == 'w'){
		++i;
	}else{
		return -1;
	}
	return i;
}

int main(){
	
	cin >> s;
	if(dfs(0) == s.size())
		cout << "Cat" << endl;
	else
		cout << "Rabbit" << endl;
	
	return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
  int n = 8;
  int k;
  cin >> k;

  vector<pair<int,int>> q(k);
  for(int i=0;i<k;i++){
    int a,b;
    cin >> a >> b;
    q[i] = make_pair(a,b);
  }

  vector<int> order(n);
  for(int i=0;i<n;i++) order[i] = i;

  do{
    bool flag = false;
    for(int i=0;i<k;i++){
      if(order[q[i].first] != q[i].second){
        flag = true;
        break;
      }
    }
    if(flag) continue;

    flag = true;
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        if(abs(j-i) == abs(order[j]-order[i])){
          flag = false;
        }else if(abs(j-i)==1 && abs(order[j]-order[i])==1){
          flag = false;
        }
      }
    }
    if(flag){
      break;
    }
  }while(next_permutation(order.begin(),order.end()));

  vector<vector<char>> ans(n,vector<char>(n));
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(order[i] == j){
        ans[i][j] = 'Q';
      }else{
        ans[i][j] = '.';
      }
    }
  }

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


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

int N, K;
int num_one_have_no_okasi;
std::vector<int> d;
std::vector<int> A;

int main() {
  std::cin >> N >> K;
  d.assign(K, 0);
  A.assign(N, 0);
  for (int i = 0; i < K; i++) {
    std::cin >> d[i];
    for (int j = 0; j < d[i]; j++) {
      int A_buf = 0;
      std::cin >> A_buf;
      --A_buf;
      A[A_buf] = 1;
    }
  }
  for (int i = 0; i < N; i++) {
    if (A[i] == 0) {
      ++num_one_have_no_okasi;
    }
  }
  std::cout << num_one_have_no_okasi << std::endl;
}

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

int main()
{
	int a, b, c, x, d=0;
	cin >>a >> b>> c;
	
	for (x = a; x <= b; x++){
		if(c % x == 0){
			d++;
		}
	}
	cout << d << endl;
	return 0;
}

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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
#define ll long long

int main(){
  int x, a, b;
  cin >> x >> a >> b;
  int after = x-a;
  puts(after%b)
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#include<assert.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define INF 0x3f3f3f3f
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod=1000000007;
const double PI = acos(-1.0);
const double epsilon = PI / 180.0;//角度转弧度 
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N = 1e6+10, M = 1e6+10;
string s, t;
int main() {
	cin>>s>>t;
	int ans = INF;
	for(int i = 0;i < s.length();i++) {
		if(i + t.length() > s.length()) break;
		int res = 0;
		for(int j = 0;j < t.length();j++) {
			if(s[i + j] != t[j]) res++;
		}
		ans = min(ans, res);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3620
while 1:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        exit()
    for i in range(h):
        for j in range(w):
            if j == w - 1:
                print('#')
            elif j == 0 or i == 0 or i == h - 1:
                print('#', end='')
            else:
                print('.', end='')
    print()



Measured memory_bytes: 6996
S = str(input())
T = str(input())


n = len(S) - len(T) + 1
ans = len(S)

for i in range(n): # スタート位置を全探索
    tmp = 0
    for j in range(len(T)):
        if S[i + j] != T[j]:
            tmp += 1
    ans = min(ans, tmp)

print (ans)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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;
}

int check(string s, int l, int r) {
  while(l < r) {
    if(s[l] != s[r]) {
      return 0;
    }
    l++;
    r--;
  }
  return 1;
}
int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  string s;
  cin >> s;
  int n = s.size();
  if(check(s, 0, n - 1) && check(s, 0, (n - 1) / 2 - 1) && check(s, (n + 3) / 2 - 1, n - 1))
    cout << "Yes\n";
  else
    cout << "No\n";
  // cout << ans << endl;
  return 0;
}



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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define bug( x ) cerr << #x << '=' << x << '\n' ;


int n , m , c;



int main(){

	IOS

	cin >> n >> m >> c ;

	int B[m] , A[n][m];

	for (int i = 0; i < m; ++i)
	{
		cin >> B[i] ;
	}

	int calculate = 0 , cnt = 0;

	for (int i = 0; i < n; ++i)
	{
		for(int j=0 ; j<m ; j++){

			cin >> A[i][j];

			calculate += (A[i][j] * B[j]) ;
		}

		if(calculate + c > 0)cnt++;

		calculate = 0 ;
	}

	cout << cnt << '\n';


}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<set>

const int N_MAX = 100000;
int x[N_MAX];
int y[N_MAX];
int sortx[N_MAX];
int sorty[N_MAX];

int par[N_MAX];
int rank[N_MAX];
std::set<int> xset[N_MAX];
std::set<int> yset[N_MAX];

void init(int n) {
	for(int i=0;i<n;i++) {
		par[i] = i;
		rank[i] = 0;
	}
}

int find(int x) {
	if(par[x] == x) {
		return x;
	} else {
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(rank[x] < rank[y]) {
		par[x] = y;
	} else {
		par[y] = x;
		if(rank[x] == rank[y]) rank[x]++;
	}
}

int main() {
	int n;
	scanf("%d", &n);
	for(int i=0;i<n;i++) {
		scanf("%d %d", &x[i], &y[i]);
	}
	init(n);
	for(int i=0;i<n;i++) {
		sortx[i] = i;
		sorty[i] = i;
	}
	std::sort(sortx, sortx + n, [](int i, int j) -> int { return x[i] < x[j]; });
	std::sort(sorty, sorty + n, [](int i, int j) -> int { return y[i] < y[j]; });
	for(int i=1;i<n;i++) {
		if(x[sortx[i-1]] == x[sortx[i]]) {
			unite(sortx[i-1], sortx[i]);
		}
		if(y[sorty[i-1]] == y[sorty[i]]) {
			unite(sorty[i-1], sorty[i]);
		}
	}
	for(int i=0;i<n;i++) {
		int j = find(i);
		xset[j].insert(x[i]);
		yset[j].insert(y[i]);
	}
	long long ans = 0;
	for(int i=0;i<n;i++) {
		if(par[i] == i) {
			ans += xset[i].size() * yset[i].size();
		}
	}
	printf("%lld\n", ans - n);
	return 0;
}


Measured memory_bytes: 16640
#include <iostream>

using namespace std;

int main(){
    int a;
    int b;
    int c;
    int d;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cout << (a + b + c + d) / 60 << endl;
    cout << (a + b + c + d) % 60 << endl;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a,b; cin>>a>>b;
	if(a+b<10) cout<<a+b;
	else cout<<"error";
	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
#include <unordered_map>

using namespace std;
typedef long long  ll;

int main()
{
	ll K;
	string str;
	cin >> str >> K;
	ll cnt = 0;
	char focus = str[0];
	ll ans = 0;
	for (size_t i = 0; i < str.size(); i++)
	{
		if (str[i] == focus)
		{
			cnt++;
		}
		else
		{
			ans += cnt / 2;
			focus = str[i];
			cnt = 1;
		}
	}
	if (cnt == str.size())
	{
		cout << K * cnt / 2 << endl;
		return 0;
	}
	ans += cnt / 2;
	ans *= K;
	ll a = 0, b = 0;
	focus = str[0];
	while (focus == str[a])
	{
		a++;
		if (str[a] != focus)
		{
			break;
		}
	}
	focus = str[str.size() - 1];
	while (focus == str[str.size() - 1 - b])
	{
		b++;
		if (str[str.size() - 1 - b] != focus) break;
	}
	if (str[0] == str[str.size() - 1])
		ans = ans - (K - 1) * (a / 2 + b / 2 - (a + b) / 2);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i, k) for(int i=0; i < (int)k; i++)
int main(){
  int L;
  cin>>L;
  int H[L],ans=0,best;
  const int inf=100000000;

  rep(i, L) cin >> H[i];
  best = inf;

  for(int i=0; i<100; i++){
    ans = 0;
    rep(j, L){
      ans += (H[j] - i) * (H[j] - i);
    }
    best = min(best, ans);
  }
  cout << best;

  return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.size()-2;i++)
	{
		if(s[i]==s[i+1] && s[i+1]==s[i+2])
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	
	
}

Measured memory_bytes: 3580
#include <stdio.h>
int main(void) {
	int n;
	int a[100];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if (a[i] % 2 == 0) {
			if (a[i] % 3 != 0 && a[i] % 5 != 0) {
				printf("DENIED\n");
				return 0;
			}
		}
	}
	printf("APPROVED\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int n;
  	cin>>n;
    int a[11000];
    int ans=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        while(a[i]%2==0){
            a[i]/=2;
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std ;

const int MAX = 27 ;

int n , q ;

string s ;

set<int>ss[MAX] ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	cin>>s ;
	cin>>q ;
	for(int i = 0 ; i < n ; ++i)
		ss[(s[i] - 'a')].insert(i) ;
	while(q--)
	{
		int t , x ; 
		cin>>t>>x ;
		--x ;
		if(t == 1)
		{
			char c ;
			cin>>c ;
			ss[(s[x] - 'a')].erase(x) ;
			s[x] = c ;
			ss[(s[x] - 'a')].insert(x) ;
		}
		else if(t == 2)
		{
			int y; 
			cin>>y ;
			--y ;
			int ans = 0 ;
			for(int i = 0 ; i < 26 ; ++i)
			{
				if(ss[i].size() == 0)
					continue ;
				int a = *ss[i].rbegin() ;
				if(a < x)
					continue ;
				a = *ss[i].lower_bound(x) ;
				if(a <= y)
					ans++ ;
			}
			cout<<ans<<"\n" ;
		}
	}
	return 0 ;
}		

Measured memory_bytes: 24220
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define llong long long
using namespace std;

const int N = 4000;
struct Edge
{
	int v,nxt;
} e[(N<<1)+2];
int fe[N+3];
int fa[N+3];
int dep[N+3];
int n,m,en;

void addedge(int u,int v)
{
	en++; e[en].v = v;
	e[en].nxt = fe[u]; fe[u] = en;
}

int dfs(int u)
{
	if(dep[u]>m) return 0;
	int ret = (u<=n);
	for(int i=fe[u]; i; i=e[i].nxt)
	{
		if(e[i].v==fa[u]) continue;
		fa[e[i].v] = u;
		dep[e[i].v] = dep[u]+1;
		ret += dfs(e[i].v);
	}
	return ret;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1; i<n; i++)
	{
		int x,y; scanf("%d%d",&x,&y);
		addedge(x,i+n); addedge(i+n,x);
		addedge(y,i+n); addedge(i+n,y);
	}
	int ans = 0;
	for(int i=1; i<=n+n-1; i++)
	{
		fa[i] = 0; dep[i] = 0;
//		printf("i%d:\n",i);
		int tmp = dfs(i);
		ans = max(ans,tmp);
	}
	ans = n-ans;
	printf("%d\n",ans);
	return 0;
}
/*
16 6
1 2
2 3
3 4
3 5
5 6
5 7
5 8
1 9
9 10
10 11
10 12
1 13
13 14
14 15
1 16
*/

Measured memory_bytes: 384
#include<stdio.h>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
    if(a>0&&b>0)
	{
		printf("Positive");
	}
	else if(a<=0&&b>=0)
	{
		printf("Zero");
	}
	else if(a<0&&b<0&&(b-a)%2==0){
		printf("Negative");
	}
	else{
		printf("Positive");
	}
	
}

Measured memory_bytes: 128
/*
	0067:The Number of Island
*/
#include	<iostream>
#include	<string>

using namespace std;

int field[12][12] = { 0 };

void draw(int x, int y);

int main(void) {
	string str;
	int c;
	while(1) {
		c = 0;
		for(int i = 0; i < 12; i++) {
			cin >> str;
			for(int j = 0; j < 12; j++) {
				if(str[j] == '1') {
					field[i][j] = 1;
				}
			}
		}
		if( cin.eof() ) {
			break;
		}
		for(int i = 0; i < 12; i++) {
			for(int j = 0; j < 12; j++) {
				if(field[i][j] == 1) {
					draw(i, j);
					c++;
				}
			}
		}
		cout << c << endl;
	}
}

void draw(int x, int y) {
	field[x][y] = 0;
	//上側検索
	if(field[x][y-1] == 1 && y != 0) {
		draw(x, y-1);
	}
	//下側検索
	if(field[x][y+1] == 1 && y != 11) {
		draw(x, y+1);
	}
	//右側検索
	if(field[x+1][y] == 1 && x != 11) {
		draw(x+1, y);
	}
	//左側検索
	if(field[x-1][y] == 1 && x != 0) {
		draw(x-1, y);
	}
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  string s = readString();
  for (int i = 0; i < s.size(); i += 2)
    std::cout << s[i];
}


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

int main(){
  int i,j,cnt;
  string s;
  cin>>s;
  cnt=0;
  for(i=0;i<s.size()-1;i++){
    if(s[i+1]!=s[i])cnt++;
  }
  cout<<cnt;
}

Measured memory_bytes: 512
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)1e5 + 5;

int arr[MAXN];

ll ans;

int n;

void solve() {
    scanf("%d", &n);

    for (int i = 1; i <= n; ++i) {
        scanf("%d", &arr[i]);
    }

    for (int l = 1, r; l <= n; l = r) {
        if (arr[l] == 0) {
            r = l + 1;
            continue;
        }

        r = l;
        ll cur = 0;

        while (arr[r]) {
            cur += arr[r++];
        }

        ans += (cur >> 1);
    }

    printf("%lld\n", ans);
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define INF 1<<29
using namespace std;
int d[150][150];
void wa_syaru(int n,int s,int g);
main(){
  int n,k;
  int num;
  while(1){
    cin>>n>>k;
    if(n==0&&k==0) break;
    fill_n(*d,150*150,INF);
    for(int i=0;i<=n;i++){
      d[i][i]=0;
    }
    for(int i=0;i<k;i++){
      cin>>num;
      if(num==0){
	int s,g;
	cin>>s>>g;
	cout<< (d[s][g]==INF ? -1 : d[s][g]) <<endl;
      }
      else{
	int s,g,c;
	cin>>s>>g>>c;
	d[s][g]=d[g][s]=min(d[s][g],c);
	wa_syaru(n,s,g);
      }
    }
  }
}
void wa_syaru(int n,int s,int g){
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      d[i][j] = min(d[i][j],d[i][s]+d[s][g]+d[g][j]);
      d[i][j] = min(d[i][j],d[i][g]+d[g][s]+d[s][j]);
    }
  }
  return;
}

Measured memory_bytes: 1248
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] num = new int[3];
		for (int i = 0; i < 3; i++) {
			num[i] = sc.nextInt();
		}
		if (num[0] < num[1]) {
			if (num[1] < num[2]) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}

		} else {
			System.out.println("No");
		}
		sc.close();
	}

}


Measured memory_bytes: 26148
#include<stdio.h>
#include<math.h>
int prime(int a)
{	int i,x;
	for(i=2;i<=(int)sqrt(a);i++)
	{
		if(a%i==0)
		{
			return 0;
		}
	}
	return 1;
}
int main()
{
	int n,a,i,count=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a);
		if(prime(a))
		{
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 596
#pragma GCC optimize ("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

#define DEBUG 0
#define dd if (DEBUG)

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, A) for (auto & a : A)
#define all(a) (a).begin (), (a).end ()
#define rall(a) (a).rbegin (), (a).rend ()
#define sz(a) (int) (a).size ()
#define szl(a) (int) (a).length ()
#define FASTIO cin.sync_with_stdio (0); cin.tie (0); cin.exceptions (cin.failbit);

typedef long long ll;
typedef pair <int, int> pii;
#define f first
#define s second
#define mp(a, b) make_pair((a), (b))
typedef vector <int> vi;
typedef vector <vi> mi;
typedef vector <ll> vll;
typedef vector <vll> mll;
#define pb(a) push_back ((a))

const ll MOD = 1e+9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int INFi = 0x3f3f3f3f;
const ll MAXN = 3e+3+7;

// 00:20:00h

int main ()
{
    FASTIO;
    int i, j, n;
    cin >> n;
    vi A (n);
    trav (a, A)
        cin >> a;
    mll dp (n, vll (n));
    trav (v, dp)
        trav (a, v)
            a = 0;
    for (i = 0; i < n; ++i)
        dp[i][i] = A[i];
    for (i = 1; i < n; ++i)
        dp[i - 1][i] = max (A[i - 1], A[i]);
    for (i = 2; i < n; ++i)
    {
        for (j = i; j < n; ++j)
        {
            dp[j - i][j] = max (A[j] + min (dp[j - i][j - 2], dp[j - i + 1][j - 1]),
                    A[j - i] + min (dp[j - i + 1][j - 1], dp[j - i + 2][j]));
        }
    }
    dd for (i = 0; i < n; ++i)
    {
        for (j = 0; j < n; ++j)
            printf ("% 5lld", dp[i][j]);
        printf ("\n");
    }
    dd printf ("\n");
    if (sz(A) > 1)
        cout << dp[0][sz(A) - 1] - min (dp[0][sz(A) - 2], dp[1][sz(A) - 1]);
    else
        cout << dp[0][sz(A) - 1];
    cout << '\n';

    return 0;
}



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

int main(){
  string s;
  cin >> s;
  long long int ans=0;
  for(int i=0;i<1 << (s.size()-1);i++){
    long long int a=s.at(0)-'0';
    long long int b=0;
      for(int j=1;j<s.size();j++){
        if(i&(1 << (j-1))){
          a=a*10+(s.at(j)-'0');
        }else{
          b+=a;
          a=s.at(j)-'0';
        }
      }
      b+=a;
      ans+=b;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3584
#include <iostream>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 15, INF = 1e9 + 5;

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

	char a[N][N];
	// bool mark[N][N] = {0};
	int ways[N][N] = {0};

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			cin >> a[i][j];

	ways[1][1] = 1;
	int ctr = 0;

	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= m; ++j)
		{
			if (a[i][j] == '#')
				++ctr;

			if (i == 1 and j == 1)
				continue;

			if (a[i][j] == '.')
				continue;

			ways[i][j] = ways[i-1][j] + ways[i][j-1];
		}
	}

	if (ways[n][m] and ctr == n+m-1)
		cout << "Possible";

	else
		cout << "Impossible";

	// int i = 1, j = 1;

	// if (a[i][j] == '.')
	// {
	// 	cout << "Impossible";
	// 	return 0;
	// }

	// mark[i][j] = true;

	// while (i != n or j != m)
	// {
	// 	if (i == n)
	// 	{
	// 		if (a[i][j+1] == '.')
	// 		{
	// 			cout << "Impossible";
	// 			return 0;
	// 		}

	// 		++j;
	// 		mark[i][j] = true;
	// 	}

	// 	else if (j == m)
	// 	{
	// 		if (a[i+1][j] == '.')
	// 		{
	// 			cout << "Impossible";
	// 			return 0;
	// 		}

	// 		++i;
	// 		mark[i][j] == true;
	// 	}

	// 	else if (a[i+1][j] == a[i][j+1])
	// 	{
	// 		cout << "Impossible";
	// 		return 0;
	// 	}

	// 	else if (a[i+1][j] == '#')
	// 	{
	// 		++i;
	// 		mark[i][j] = true;
	// 	}

	// 	else
	// 	{
	// 		++j;
	// 		mark[i][j] = true;
	// 	}
	// }

	// for (int i = 1; i <= n; ++i)
	// {
	// 	for (int j = 1; j <= m; ++j)
	// 	{
	// 		if (a[i][j] == '#' and !mark[i][j])
	// 		{
	// 			cout << "Impossible";
	// 			return 0;
	// 		}
	// 	}
	// }

	// cout << "Possible";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=998244353;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int n,s[100010];
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n)cin>>s[i];
    int ans=0;
    for(int c=1;c<n-1;c++){
        int cur=0;
        for(int k=1;(k+1)*c<n-1;k++){
            cur+=s[n-1-k*c]+s[k*c];
            if((n-1)%c==0){
                if(n-1-k*c<=k*c)break;
            }
            chmax(ans,cur);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4420
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=2e5+10;
int a[maxn];
main(){
    int n,x;
    cin>>n>>x;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    int ans=0;
    for(int i=1;i<n;++i){
        if(a[i]+a[i+1]>x){
            int d=a[i]+a[i+1]-x;
            int num=a[i+1];
            ans+=min(num,d);
            a[i+1]=max(0ll,num-d);
            d-=min(num,d);
            if(d>0){
                ans+=d;
                a[i]-=d;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>=1&&a<=9&&b>=1&&b<=9)
    {
        cout<<a*b<<endl;
    }
    else
        cout<<"-1"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define lw 4280

int main(void){
	int n, i, j, x[6] = {0};
	double a;
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%lf", &a);
	if (a < 165.0)
		x[0] += 1;
	else if (a <170.0)
		x[1] += 1;
	else if (a <175.0)
		x[2] += 1;
	else if (a < 180.0)
		x[3] += 1;
	else if(a < 185.0)
		x[4] += 1;
	else
		x[5] +=1;
	}
	for (i = 0; i < 6; i++){
		printf("%d:", i+1);
		if (x[i] != 0)
		for (j = 0; j < x[i]; j++){
			printf("*");
		}
		printf("\n");
	}
	return 0;
}

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

int main()
{
    int N, R;
    cin >> N >> R;
    if(N >= 10){
        cout << R << endl;
    }
    else{
        cout << R + 100 * (10 - N) << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 504
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

		String s;
		String t[];
		while((s = r.readLine()) != null){
			t = s.split("[ ]");
			System.out.println(Integer.parseInt(t[0])+ Integer.parseInt(t[1]));
		}
	}
}

Measured memory_bytes: 10000
#include <bits/stdc++.h>
#define de(x) cout << #x << "=" << x << ", "
#define dd cout << '\n';
#define XinAi ios::sync_with_stdio(0), cin.tie(0);
#define F first
#define S second
#define int long long
using namespace std;
typedef pair<int,int> pii;
const int N = 1e13, M = sqrt(N)+10;

int np[M];

signed main()
{
    for (int i=2; i<M; i++)
        if (!np[i])
            for (int j=i*2; j<M; j+=i)
                np[j] = 1;
    int n, res=0;
    cin >> n;
    for (int i=2; i<M; i++)
    {
        if (np[i]) continue;
        if (n % i == 0)
        {
            int owo = 0;
            while (n%i == 0) n /= i, owo++;
            for (int j=1; owo-j>=0; owo-=j,j++,res++);
        }
    }
    if (n > 1) res++;
    cout << res << '\n';
}


Measured memory_bytes: 28324
#include<stdio.h>

int main()
{
    int x,a,b,k,j;
    scanf("%d %d %d",&x,&a,&b);
				if(x>a){
    k=x-a;
								}
				else{
								k=a-x;
				}
				if(x>b){
    j=x-b;
								}
				else{
								j=b-x;
				}
    if(k>j){
    printf("B\n");
    }
else{
printf("A\n");
}
return 0;
}
    

Measured memory_bytes: 128