akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
using namespace std;

string str;

bool solve(int p, char c) {
	for (int i = p+1; i < str.size(); i++) {
		if (str[i] == ']' || str[i] == ')') {
			if (str[i] == c) {
				str[p] = str[i] = ' ';
				return 1;
			} else {
				break;
			}
		} else if (str[i] == '(' || str[i] == '[') {
			char t = (str[i] == '(' ? ')' : ']');
			if (!solve(i, t)) {
				break;
			}
		}
	}
	return 0;
}

int main()
{	
	while (getline(cin, str), str != ".") {
		bool f = 0;

		for (int i = 0; i < str.size(); i++) {
			if (str[i] == '(' || str[i] == '[') {
				f = 1;
				char t = (str[i] == '(' ? ')' : ']');
				if (solve(i, t)) f = 0;
			} else if (str[i] == ')' || str[i] == ']') f = 1;
			if (f) break;
		}
		if (!f) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1176
using System;
using System.Linq;
using static System.Console;
namespace Atcoder{
    public class Program{
        static void Main(string[] arg){
            int n = int.Parse(Console.ReadLine());
            int[] w = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
            int i = 0,j = n;
            int sum1 = 0,sum2 = 0;
            while(i != j){
                if (sum1 < sum2){
                    sum1 += w[i];
                    i++;
                } else {
                    j--;
                    sum2 += w[j];
                }
            }
            Console.WriteLine(Math.Abs(sum1-sum2));
        }
    }
}

Measured memory_bytes: 13268
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include <cstdlib>
#include <string>
#include <typeinfo>
#include<queue>
#include<stack>
#include<set>

using namespace std;
vector<pair<long long, long long> >V;

long long n, m;
long long a[100005], b[100005];
long long answer;

int main(){
  cin >> n >> m;
  for(int i = 0; i < n; ++i){
    cin >> a[i] >> b[i];
    V.push_back(make_pair(a[i], b[i]));
  }
  sort(V.begin(), V.end());
  long long cnt = m;
  long long place = 0;
  while(cnt > 0){
    if(cnt < V[place].second){
      answer += cnt * V[place].first;
    }else{
      answer += V[place].first * V[place].second;
    }
    cnt -= V[place].second;
    place++;
  }
  cout << answer << endl;
}

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

int main(){
    int a,b;
    cin >> a;
    cin >> b;
    if(a==1 && b==2)cout << 3 << endl;
    else if(a==2 && b==1)cout << 3 << endl;
    else if(a==1 && b==3)cout << 2 << endl;
    else if(a==3 && b==1)cout << 2 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <map>
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

const int mod = 998244353;
string S;
map<string,int> f;
map<string,int> g;

int F(string s);

int G(string s)
{
    if (g.find(s) != g.end())
        return g[s];
    if (s.size() == 1)
        return g[s] = s[0] - '0' + 1;
    int &t = g[s];
    for (int i = 1; i < s.size(); i++)
        if (s.size() % i == 0)
        {
            string ss = "";
            for (int j = 0; j < i; j++)
            {
                char ch = s[j];
                for (int k = 1; i * k + j < s.size(); k++)
                    if (s[i * k + j] == '0')
                        ch = '0';
                ss += ch;
            }
            t = (t + F(ss)) % mod;
        }
    return t;
}

int F(string s)
{
    if (f.find(s) != f.end())
        return f[s];
    int &t = f[s];
    for (int i = 1; i <= s.size(); i++)
        t = (t + 1LL * G(s.substr(0,i)) * F(s.substr(i,s.size() - i)) % mod) % mod;
    return t;
}

int main()
{
    cin >> S;
    f[""] = 1;
    printf("%d\n",F(S));

    return 0;
}


Measured memory_bytes: 12928
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);

    string s; cin >> s;
    cout << (s == "ABC" ? "ARC" : "ABC") << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
    unsigned long long n; cin >> n;
    
    unsigned long long ans = 0;
    
    auto div = n;
    while(div > 1) {
        auto d = n / div;
        auto r = n % div;
        if (d == r) {
            ans += div;
            div = n / (n / div + 1);
        } else if (r > d){
            div = n / (n / div + 1);
        } else {
            div--;
        }
    }

    cout << ans << endl;
}

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

int main(){

    ll a,b,h,m;
    cin >> a >> b >> h >> m;

    double ha = (h *60 + m) * (36.0/72.0);
    double ma = m * 6;

    double ans = a*a + b*b - 2* a * b * cos( (abs(ha - ma)* acos(-1)/180.0) );
    cout << setprecision(15) <<sqrt(ans) << endl;
    return 0;
}


Measured memory_bytes: 4136
a,b=1,0
while a>0:
    a=int(input())
    if a==0:
        break
    b=1000-a
    c=b//500
    d=b%500//100
    e=b%100//50
    f=b%50//10
    g=b%10//5
    h=b%5
    print(c+d+e+f+g+h)


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

#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define phi 3.1415926535
 
using namespace std;
 
ll tc, cnt = 0, number, many, total = 0;
int rmove[4] = {0, 0, -1, 1};
int cmove[4] = {1, -1, 0, 0};



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    // g++ -std=c++11 Default.cpp  -o test

    int arr[5];
    for(int i = 0; i < 5; i++)
        cin >> arr[i];

    int answer;
    for(int i = 0; i < 5; i++)
    {
        if(arr[i] == 0)
        {
            answer = i + 1;
        }
    }

    cout << answer << endl;
    
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
    return 0;
}

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


int main(){
   int n,k;
   cin >> n >>k;
   int count=0;
   for(int i=0;i<n;i++){
   	int inp;
   	cin >> inp;
   	if(inp>=k)count++;
   }
   cout << count;
}

Measured memory_bytes: 256
A, B, C, X, Y = gets.split.map(&:to_i)
a, b, c = 0, 0, 0 # 枚数
ret = 10000000000
X.downto(0) do |a|
    c = (X - a) * 2
    b = [0, Y - c*2].max
    next if b < 0
    if X <= a + c.div(2) && Y <= b + c.div(2)
        ret = [ret, a*A + b*B + c*C].min
    end
end
Y.downto(0) do |b|
    c = (Y - b) * 2
    a = [0, X - c*2].max
    if X <= a + c.div(2) && Y <= b + c.div(2)
        ret = [ret, a*A + b*B + c*C].min
    end
end
[2*X,2*Y].max.downto(0) do |c|
    a = [0, X - c.div(2)].max
    b = [0, Y - c.div(2)].max
    if X <= a + c.div(2) && Y <= b + c.div(2)
        ret = [ret, a*A + b*B + c*C].min
    end
end
# end
puts ret

Measured memory_bytes: 1788
n,m = gets.split(" ")
k_ary = []
while k = gets do
    k = k.split(" ").map(&:to_i)
    k.delete_at(0)
    k_ary.push(k)
end

fav_list = Hash.new(0)
k_ary.each do |person|
    detect_list ||= person
    person.each do |menu|
        fav_list[menu] += 1
    end
end

count = 0
n = n.to_i
fav_list.values.each do |v|
    count += 1 if v == n
end
puts count


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

int main() {
  ll q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  ll one = min(4 * q, min(2 * h, s));
  ll two = min(2 * one, d);
  ll ans = n / 2 * two;
  if (n % 2 != 0) {
    ans += one;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
ll A[100005];
ll S[100005];
ll Q;
map<ll,ll> mp;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;
rep(i,N){
	cin>>A[i]; 
	S[0]+=A[i];
	mp[A[i]]++;
}
cin>>Q;
rep1(i,Q+1){
	ll B,C;
	cin>>B>>C;
	if(B>=C) S[i]=S[i-1]-mp[B]*abs(B-C);
	else S[i]=S[i-1]+mp[B]*abs(B-C);
	mp[C]+=mp[B];
	mp[B]=0;
	cout<<S[i]<<endl;
}


}
	

Measured memory_bytes: 11120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> g[200005];
ll col[200005],son[200005],colson[200005],ans[200005],n,u,v;
ll f(ll n){return n*(n+1)/2;}
void dfs(ll u,ll par)
{
	ll temp=colson[col[u]],v;
	for(ll i=0;i<g[u].size();i++){
		v=g[u][i];
		if(v==par) continue;
		colson[col[u]]=0;
		dfs(v,u);
		son[u]+=son[v];
		ans[col[u]]-=f(son[v]-colson[col[u]]);
	}
	colson[col[u]]=temp+son[u];
}
int main(void)
{
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++){
		scanf("%lld",&col[i]);
		son[i]=1;
		ans[i]=f(n);
	}
	for(ll i=0;i<n-1;i++){
		scanf("%lld%lld",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1,0);
	for(ll i=1;i<=n;i++) printf("%lld\n",ans[i]-f(n-colson[i]));
}

Measured memory_bytes: 39492
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}


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


	int N = getint(), T = getint();
	int saishou = 1e9;
	int rieki = 0;
	ll kazu = 0;
	rep(i, N) {
		int a = getint();
		int b = a - saishou;
		if (rieki == b) kazu++;
		if (rieki < b) {
			rieki = b;
			kazu = 1;
		}
		chmin(saishou, a);
	}

	printf("%lld", kazu);

	Would you please return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int r = sc.nextInt();
		int c = sc.nextInt();
		int a1 = sc.nextInt();
		int a2 = sc.nextInt();
		int b1 = sc.nextInt();
		int b2 = sc.nextInt();
		
		int x = Math.abs(a1-b1);
		int y = Math.abs(a2-b2);
		x = Math.min(x, r-x);
		y = Math.min(y, c-y);
		
		int f = 1;
		if(r == 2*x) f *= 2;
		if(c == 2*y) f *= 2;
		
		int z = Math.min(x, y);
		BigInteger bi = BigInteger.ONE;
		for(int i=0;i<z;i++){
			bi = bi.multiply(new BigInteger(String.valueOf(x+y-i)));
			bi = bi.divide(new BigInteger(String.valueOf(i+1)));
		}
		bi = bi.multiply(new BigInteger(String.valueOf(f)));
		bi = bi.mod(new BigInteger("100000007"));
		System.out.println(bi);
	}	
}

Measured memory_bytes: 20520
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int z = Integer.parseInt(sc.next());
		int w = Integer.parseInt(sc.next());
		if (n == 1) {
			int a = Integer.parseInt(sc.next());
			System.out.println(Math.abs(w - a));
			return;
		}
		for (int i = 0; i < n - 2; i++)
			sc.next();
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		System.out.println(Math.max(Math.abs(a - b), Math.abs(w - b)));
	}
}

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

#define int long long

// #include "debug.cpp"

int32_t main(){
	int n, x, m, i, j;
	cin >> n >> x >> m;
	if(n <= 1000000){
		int arr[n];
		arr[0] = x;
		int ans = x;
		for(i=1; i<n; i++){
			arr[i] = arr[i-1]*arr[i-1] % m;
			ans += arr[i];
		}

		cout << ans << "\n";
		return 0;
	}

	map<int, int> mp;
	int arr[1000000];
	arr[0] = x;
	mp[x] = 0;

	int cycle_length, startval, cycle_start_ind;
	for(i=1; i<n; i++){
		arr[i] = arr[i-1]*arr[i-1] % m;
		if(mp.find(arr[i]) != mp.end()){
			cycle_length = i-mp[arr[i]];
			cycle_start_ind = mp[arr[i]];
			startval = arr[i];
			break;
		}
		else{
			mp[arr[i]] = i;
		}
	}

	int ans = 0, ind = 0;
	for(i=0; i<cycle_start_ind; i++){
		ans += arr[i];
	}

	n -= cycle_start_ind+1;

	int cycle_sum = 0;
	for(i=cycle_start_ind; i<cycle_start_ind + cycle_length; i++){
		cycle_sum += arr[i];
	}

	// debug(cycle_start_ind, cycle_length, cycle_sum);

	ans += n/cycle_length * cycle_sum;
	int rem = n%cycle_length;

	for(i=cycle_start_ind; i<=cycle_start_ind+rem; i++){
		ans += arr[i];
	}

	// 492443256176507


	// print(mp);

	cout << ans << "\n";
}

Measured memory_bytes: 11128
s=list(input())
n=len(s)
#print(n)
ans=0
for bit in range(1 << (n - 1)):
    # 各場合で式 f を生成する
    #print("bit",bit,bin(bit))
    f = s[0]

    for i in range(n - 1):
        if bit & (1 << i):
            # フラグが立っているならば "+" を式の末尾に追加する
            f += "+"
        f += s[i + 1]
        #print("i",i,"1 << i",bin(1 << i),"f",f)
    ans += sum(map(int, f.split("+")))

print(ans)


Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;	cin >> s;
  string t=s;
  reverse(t.begin(),t.end());
  int c=0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)!=t.at(i))	c++;
  }
  cout << c/2;
}

Measured memory_bytes: 3604
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
 
public class Main {
 
    Scanner scanner = new Scanner(System.in);
 
    public static void main(String[] args) {
        new Main().compute();
    }
 
    void compute() {
        int N = scanner.nextInt();
        HashMap<Integer,Boolean> used=new HashMap<>();
        for (int i = 0; i < N; i++) {
            int current = scanner.nextInt();
            if(used.containsKey(current)){
                used.remove(new Integer(current));
            }else{
                used.put(current,true);
            }
        }
        System.out.println(used.size());
    }
}

Measured memory_bytes: 63104
#include <bits/stdc++.h>
using namespace std;
const int M = 262150;
typedef pair<int, int> par;
int n, N, R[M], low[M], hig[M], val[M];
priority_queue<par, vector<par>, greater<par>> q;
vector<par> e[M];

int main() {
  scanf("%d", &n);
  N = 1 << n;
  for (int i = 1; i < N; i++) {
    R[i] = (R[i >> 1] >> 1) | ((i & 1) << n - 1);
  }
  for (int i = 0; i < N; i++) {
    scanf("%d", val + i);
    val[i]--;
  }
  for (int i = N - 1; ~i; i--) {
    hig[i] = N - 1;
    if (~val[i]) {
      hig[i] = val[i];
    }
    for (int j = 0; j < n; j++) {
      if (!(i >> j & 1)) {
        hig[i] = min(hig[i], hig[i ^ 1 << j]);
      }
    }
  }
  for (int i = 0; i < N; i++) {
    low[i] = 0;
    if (~val[i]) {
      low[i] = val[i];
    }
    for (int j = 0; j < n; j++) {
      if (i >> j & 1) {
        low[i] = max(low[i], low[i ^ 1 << j]);
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (low[i] > hig[i]) {
      return puts("NO"), 0;
    } else {
      e[low[i]].push_back(make_pair(hig[i], i));
    }
  }
  for (int i = 0; i < N; i++) {
    for (auto x : e[i]) {
      q.push(x);
    }
    if (q.empty() || q.top().first < i) {
      return puts("NO"), 0;
    }
    val[q.top().second] = i;
    q.pop();
  }
  puts("YES");
  for (int i = 0; i < N; i++) {
    printf("%d%c", val[R[i]] + 1, (i == N - 1)[" \n"]);
  }
  return 0;
}



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

int main() {
    int x, y;

    while (1) {
        cin >> x >> y;
        if ((x == 0) && (y == 0)) {
            break;
        }

        if (x > y) {
            cout << y << " " << x << endl;
        } else {
            cout << x << " " << y << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	string s;
	int w;
	cin>>s;
	scanf("%d",&w);
	int l=s.size();
	for(int i=0;i<l;i+=w)
	{
		cout<<s[i];
	}
	return 0;
}

Measured memory_bytes: 3688
// ------------------------------------
// Date:2018/ 3/ 2
// Problem:AOJ DPL 0-1 Knapsack Problem 1_b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

//static const int MOD = 1000000007;

// dp[今見てる品物の個数+1][まだ詰め込める量]
int dp[101][10101];

// v:value / w:weight
int v[1010];
int w[1010];

// N:品物の個数 / W:ナップサックの容量
int N, W;

int main()
{
  // 初期化
  memset(dp, 0, sizeof(dp));
  memset(v, 0, sizeof(v));
  memset(w, 0, sizeof(w));
  scanf("%d %d", &N, &W);
  REP(i, N) {
    scanf("%d %d", &v[i], &w[i]);
  }
  
  REP(num, N) {
    REP(weight, W+1) {
      if (weight < w[num]) {
        // 見ている品物の重さが、まだ詰め込める量より多いとき
        dp[num + 1][weight] = dp[num][weight];
      } else {
        // 詰め込むことが可能な状態で、max(詰め込まない or 詰め込む
        dp[num + 1][weight] = max(dp[num][weight],
                                  dp[num][weight - w[num]] + v[num]);
      }
    }
  }
  
  int ans = dp[N][W];
  printf("%d\n", ans);
  
  return 0;
}



Measured memory_bytes: 7216
//#define MYDEBUG
#include <bits/stdc++.h>

#ifdef MYDEBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl
#define dbp4(w,x,y,z) cout<<#w<<","<<#x<<","<<#y<<","<<#z<<": "<<w<<","<<x<<","<<y<<","<<z<<endl
#define ifcin(x) std::ifstream cin(x)
#else
#define dbp(x)
#define dbp2(x,y)
#define dbp3(x,y,z)
#define dbp4(w,x,y,z)
#define ifcin(x)
#endif
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define rep(i, from, to) for(int i=from; i<to; ++i)
#define REP(i, from, to) for(int i=from; i<=to; ++i)
using namespace std;
static const ll MAX_N = 100010 * 2;
static const ll INF = 1000000000000000000;
int N;
ll a[MAX_N], sum[MAX_N];
void solve() {
  cin >> N;
  a[0] = 0;
  sum[0] = 0;
  REP(i,1,N)
  {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  //x: sum[k] - sum[1-1] = sum[k] - sum[0]
  //y: sum[n] - sum[k+1-1] = sum[n] - sum[k]
  //k=1; k<=n-1; ++k
  ll ans = INF;
  for (int k = 1; k <= N - 1; ++k) {
    ll x = sum[k] - sum[0];
    ll y = sum[N] - sum[k];
    ans = min(ans, abs(x - y));
  }
  cout << ans << endl;
}

int main() {
  solve();
}



Measured memory_bytes: 3328
n,m = gets.split.map(&:to_i)
s = gets.chomp
t = gets.chomp

a = n.lcm(m)
b = n.gcd(m)

c = n/b
d = m/b

ss = ""
n.times{|i|
  if i%c==0
    ss += s[i]
  end
}

tt = ""
m.times{|i|
  if i%d==0
    tt += t[i]
  end
}

if ss==tt
  p a
else
  p -1
end



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

long long cnt;
int l;
int A[1000000];
int n;
vector<int>G;

void insertionSort(int A[], int n, int g){
  for(int i =g; i <n ; i++ ){
    int v = A[i]; //一時的に保存し
    int j= i -g; // g-i のところと比較する
    while(j >= 0 && A[j] > v){ //A[j]の値の方が大きいなら
      A[j + g] = A[j]; //j+gの位置，つまりもともとA[i]があった位置にA[j]を入れ
      j -= g; //jをj-gにする．これでjが負になったらループを抜ける
      cnt ++;
    }
    A[j + g] = v; //変更がなければそのままだし，入れ替わっていたらもともと保存しておいた値vを入れる
  }
}

void shellsort (int A[],int n){
  //数列Gを生成
  for(int h = 1; ;){ //無限ループ　外でint h= 1;while(1){でも多分いい
    if(h > n)break;//②ｈがnより大きければ，追加する前にループを抜ける
    G.push_back(h);//配列の後ろにhを追加する
    h = 3*h + 1; //①hを3倍し，1足す　ループ
  }
  
  for(int i = G.size()-1; i >=0; i--){ //Gを逆順にし，挿入ソートを行う
    insertionSort(A, n , G[i]);
  }
}

int main(){
  cin >> n;
  for(int i = 0; i <n ; i++){
    scanf("%d",&A[i]);
  }
  cnt = 0;
  
 shellsort(A, n);
  
  cout << G.size() << endl;
  for(int i= G.size() -1; i >= 0; i--){
    cout << G[i];
    if(i == 0) cout << endl;
    else cout << " ";
  }
  cout << cnt << endl;
  for(int i = 0; i < n; i++)cout << A[i] << endl;
}
  




Measured memory_bytes: 7048
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n,K;
    scanf("%d%d", &n, &K);

    vector<int> a(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }

    ll ans=-LINF;
    int j;
    for(i=0; i<=K; i++) {
        for(j=0; j<=K-i; j++) {
            if(i+j>n) continue;
            int k;
            for(k=0; k<=K-i-j; k++) {
                if(k>i+j) continue;

                vector<int> v;
                int p;
                for(p=0; p<i; p++) {
                    v.push_back(a[p]);
                }
                for(p=n-1; p>=n-j; p--) {
                    v.push_back(a[p]);
                }
                sort(v.rbegin(), v.rend());
                ll sum=0;
                for(p=0; p<i+j-k; p++) {
                    sum += v[p];
                }
                ans = MAX(ans, sum);
            }
        }
    }
    printf("%lld\n", MAX(0,ans));

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a,b;
		a = sc.nextInt();
		b = sc.nextInt();
		a = (a + b + 1)/2;
			System.out.println(a);
	}
}

Measured memory_bytes: 21972
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		Set<Integer> a = new HashSet<>();
		for(int i = 0;i < n;i++){
			int num = saori.saori_hayami();
			if(a.contains(num)){
				System.out.println("NO");
				return;
			} else {
				a.add(num);
			}
		}
		System.out.println("YES");
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 52516
from bisect import bisect_right, bisect_left

N = int(input())
A = [int(zz) for zz in input().split()]
B = [int(zz) for zz in input().split()]
C = [int(zz) for zz in input().split()]

A.sort()
B.sort()
C.sort()

ans = 0
for i in range(N):
    p = bisect_left(A, B[i])
    q = N - bisect_right(C, B[i])

    ans += p * q

print(ans)


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

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}

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

    if(s=="AAA" or s=="BBB"){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

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

    vector<string> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<string> b(m);
    for(int i = 0; i < m; i++){
        cin >> b[i];
    }

    for(int i = 0; i < n - m + 1; i++){
        for(int j = 0; j < n - m + 1; j++){
            bool ok = true;
            for(int k = 0; k < m; k++){
                for(int l = 0; l < m; l++){
                    if(a[i + k][j + l] == b[k][l]){
                        continue;
                    } else {
                        ok = false;
                        break;
                    }
                }
                if(!ok)break;
            }
            if(ok){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <map>           // sorted map so O(logn)
#include <unordered_map> // O(1)
typedef long long ll;
using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (u == s)
    {
        a--;
    }
    else
    {
        b--;
    }
    cout << a << " " << b << endl;
    return 0;
}


Measured memory_bytes: 3600
import java.util.Scanner;

/**
 * @author yoshizaki
 *
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        String s = scanner.next();
        String ans = "Yes";
        if(s.charAt(2) != s.charAt(3))ans = "No";
        if(s.charAt(4) != s.charAt(5))ans = "No";
        System.out.println(ans);
    }

}


Measured memory_bytes: 23508
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);
 
struct Edge {
    ll to, cost;
    Edge(ll to, ll cost):to(to),cost(cost) {}
};
 
struct Data {
    ll v, x;  // いまいる頂点v, 進んだ距離x
    Data(ll v, ll x):v(v),x(x) {}
    bool operator<(const Data& hoge) const {
        return x > hoge.x;
    }
};
 
int main() {
    ll n;
    cin >> n;
    
    vector<vector<Edge>> G(n);
    rep(i, n-1) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;  b--;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }
 
    ll q, sv;
    cin >> q >> sv;
    sv--;
 
    vl dp(n, INF);
    priority_queue<Data> Q;
    auto push = [&](ll v, ll x) {
        if(dp[v] <= x) {
            return;
        }
        dp[v] = x;
        Q.emplace(v, x);
    };
    
    // ダイクストラ法。計算量はO((V+E)*log(V))
    push(sv, 0);
    while(!Q.empty()) {
        Data hoge = Q.top();  Q.pop();
        ll v = hoge.v, x = hoge.x;
        if(dp[v] != x) {
            continue;
        }
        for(Edge e : G[v]) {
            push(e.to, x + e.cost);
        }
    }
 
    rep(i, q) {
        ll x, y;
        cin >> x >> y;
        x--;  y--;
        out(dp[x] + dp[y]);
    }
 
    re0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n;
    cin>>n;
    ll m=n/11*2,l=n%11;
    if(l>6)m+=2;
    else if(l>0) m++;
    cout<<m;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main(){
    char x[1001];
    
    while(scanf("%s", x), x[0] != '0'){
        int s = 0;
        
        for(int i = 0; x[i] != '\0'; ++i){
            s += x[i] - '0';
        }
        
        printf("%d\n", s);
    }
    
    return 0;
}


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

using namespace std;

typedef long long ll;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  cout << (n + 1) / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
_ = int(input())
A = list(map(int, input().split()))
Q = int(input())
Query = [tuple(map(int, input().split())) for _ in range(Q)]
from collections import Counter
cntr = Counter(A)
ans = sum(A)
for b, c in Query:
    if cntr.get(b) == None:
        print(ans)
        continue
    diff = (c - b) * cntr[b]
    ans += diff
    print(ans)
    cntr[c] += cntr[b]
    cntr[b] = 0

Measured memory_bytes: 31568
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define   ull unsigned long long 
const int MAX=1e6+9;
const int mod=1e9+7;
using namespace std;
int cnt[MAX];

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

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
	  cin >> A.at(i);
  }
  int sum = 0;
  for (int i = 0; i < N; i++) {
	  sum += A.at(i);
  }
  vector<int> X(N);
  for (int i = 1; i < N; i += 2) {
  	sum -= 2 * A.at(i);
  }
  X[0] = sum;
  for (int i = 1; i < N; i++) {
	X.at(i) = 2 * A.at(i - 1) - X.at(i - 1);
  }
  for (int i = 0; i < N; i++) {
	cout << X.at(i) << " ";
  }
  cout << endl;
}

Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
map<int,int> m;

while(n--)
{
	int x;
	cin>>x;
	m[x]++;
}

int ans=0;

tr(m,it)
{
	int x=it->ff,y=it->ss;
	if(y>=x)ans+=y-x;
	else ans+=y;
}
ol(ans);
return 0;
}



Measured memory_bytes: 4736
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

ll INF = (1LL << 60);

//ll dp[200001][5];

int main(){
    int N;
    cin >> N;
    ll a[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    vector<vector<ll>> dp(N + 1, vector<ll>(5, INF));

    //初期化
    dp[0][0] = 0;

    for(int i = 0; i < N; i++){
        for(int j = 0; j < 5; j++){
            for(int k = 0; k <= j; k++){
                if(j == 0 || j == 4){
                    dp[i + 1][j] = min(dp[i + 1][j], dp[i][k] + a[i]);
                }
                if(j == 1 || j == 3){
                    dp[i + 1][j] = min(dp[i + 1][j], dp[i][k] + a[i] % 2);
                    if(a[i] == 0) dp[i + 1][j] += 2;
                }
                if(j == 2){
                    dp[i + 1][j] = min(dp[i + 1][j], dp[i][k] + 1 - a[i] % 2);
                }
            }
        }
    }

    /*
    for(int i = 0; i <= N; i++){
        for(int j = 0; j < 5; j++){
            cout << setw(10) << dp[i][j] << " ";
        }
        cout << endl;
    }*/

    ll ans = INF;
    for(int j = 0; j < 5; j++){
        ans = min(ans, dp[N][j]);
    }

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

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

int main(void) {
    string a, b;
    cin >> a >> b;



    long double ans = sqrt(atoi((a + b).c_str()));

    if (ceil(ans) != floor(ans)) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <type_traits>
#include <utility>
#include <algorithm>
#include <vector>
#include <functional>
#include <string>
#include <iostream>
namespace loquat {
template <int MOD>
class modulus_integer {
public:
	typedef modulus_integer<MOD> self_type;
private:
	int m_value;
	static self_type unsafe_construct(int x) noexcept {
		self_type y;
		y.m_value = x;
		return y;
	}
public:
	modulus_integer() noexcept
		: m_value(0)
	{ }
	modulus_integer(int x) noexcept
		: m_value(x % MOD)
	{
		if(m_value < 0){ m_value += MOD; }
	}
	int operator*() const noexcept { return m_value; }
	self_type& operator=(const self_type& x) noexcept {
		m_value = x.m_value;
		return *this;
	}
	self_type operator+(const self_type& x) const noexcept {
		const int y = m_value + x.m_value;
		return unsafe_construct(y >= MOD ? y - MOD : y);
	}
	self_type operator-(const self_type& x) const noexcept {
		const int y = m_value - x.m_value;
		return unsafe_construct(y < 0 ? y + MOD : y);
	}
	self_type& operator+=(const self_type& x) noexcept {
		return (*this = *this + x);
	}
};
template <int MOD>
inline std::ostream& operator<<(
	std::ostream& os, const modulus_integer<MOD>& x)
{
	os << *x;
	return os;
}
}
using namespace std;
static constexpr int MOD = 998244353;
using mint = loquat::modulus_integer<MOD>;
int main(){
	ios_base::sync_with_stdio(false);
	string s;
	int k;
	cin >> s >> k;
	const int n = s.size();
	const int m = count(s.begin(), s.end(), '0') + 1;
	vector<int> a = { 0 };
	for(const int c : s){
		if(c == '0'){
			a.push_back(0);
		}else{
			++a.back();
		}
	}
	while(a.size() < m){
		a.push_back(0);
	}
	const int r = count(s.begin(), s.end(), '1') + 1;
	vector<vector<mint>> cur(r, vector<mint>(r, 0));
	cur[0][0] = 1;
	for(int i = 0; i < m; ++i){
		vector<vector<mint>> ht(r, vector<mint>(r + 1));
		vector<vector<mint>> vt(r + 1, vector<mint>(r));
		for(int y = 0; y < r; ++y){
			for(int x = 0; x < r; ++x){
				ht[y][x + 1] = ht[y][x] + cur[y][x];
				vt[y + 1][x] = vt[y][x] + cur[y][x];
			}
		}
		vector<vector<mint>> next(r, vector<mint>(r, 0));
		for(int y = 0; y < r; ++y){
			for(int x = 0; x < r; ++x){
				if(y <= x){
					next[y][x] =
						  ht[y][x + 1]
						+ vt[y + 1][x]
						- vt[max(0, y - a[i])][x]
						- cur[y][x];
				}else{
					next[y][x] = 0;
				}
			}
		}
		cur = move(next);
	}
	mint answer = 0;
	for(int i = 0; i < r && i <= k; ++i){
		answer += cur[i][i];
	}
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 4844
#include <stdio.h>
#define rep(i,n)for(int i=0;i<(int)(n);i++)
int main(){
    int n,m,x,c[12]={0},a[12][12]={0},y,z[12],b,d=2e9;
    scanf("%d%d%d",&n,&m,&x);
    rep(i,n){
    scanf("%d",&c[i]);
        rep(j,m){
            scanf("%d",&a[i][j]);
        }
    }
    rep(i,2){rep(j,2){rep(k,2){rep(l,2){rep(o,2){rep(p,2){rep(q,2){rep(r,2){rep(s,2){rep(t,2){rep(u,2){rep(v,2){
        y=i*c[0]+j*c[1]+k*c[2]+l*c[3]+o*c[4]+p*c[5]+q*c[6]+r*c[7]+s*c[8]+t*c[9]+u*c[10]+v*c[11];
        for(b=0;b<m;b++){
            z[b]=i*a[0][b]+j*a[1][b]+k*a[2][b]+l*a[3][b]+o*a[4][b]+p*a[5][b]+q*a[6][b]+r*a[7][b]+s*a[8][b]+t*a[9][b]+u*a[10][b]+v*a[11][b];
            if(z[b]<x)break;
        }
        if(b==m&&y<d)d = y;
    }}}}}}}}}}}}
    if(d==(int)2e9)puts("-1");
    else printf("%d",d);
    return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;cin>>n;
  bool dd=false;
  for(int i=1;i<=(n/4);i++){
  	for(int j=0;j<=i;j++){
     	if(4*j+7*(i-j)==n){
        	dd=true;
            goto yes;
        } 
    }
  }
  yes:
  if(dd){
  	cout<<"Yes"<<endl;
  }else{
  	cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
// AOJ Vol3-0380 Celsius and Fahrenheit
// 2018.12.22

//#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int main(){
    int F, C;
    
    scanf("%d", &F);
    C = (F - 30)/ 2;
    printf("%d\n", C);
    return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */
int d[100010];
int main() {
    int n;
    cin >> n;
    rep(i, n){
        cin >> d[i];
    }
    sort(d, d+n);
    int m = n / 2;
    if(d[m-1] == d[m]){
        cout << 0 << endl;
    }else{
        cout << d[m] - d[m - 1] << endl;
    }
}



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

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

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

int main()
{
    ll n, k;

    std::cin >> n >> k;

    std::vector<ll> a(n + 1);
    std::vector<int> mods(n + 1);

    rep(i, n)
    {
        std::cin >> a[i];
        a[i] += a[i - 1] - 1;
        mods[i] = a[i] % k;
    }

    ll ans = 0;

    std::map<int, ll> mp;

    mp[0] = 1;

    rep(i, n)
    {
        if (i >= k)
        {
            --mp[mods[i - k]];
        }
        ans += mp[mods[i]];
        ++mp[mods[i]];
    }

    std::cout << ans << std::endl;

    return 0;
}

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

int main() {
  
  int n;
  cin >> n;
  
  vector<double> u(n);
  
  for ( int i = 0; i < n; i++){
    cin >> u[i];
  }
  
  sort(u.begin(),u.end());
  
  double value = ( u[0] + u[1] ) / 2;
  
  for ( int i = 2; i < n; i++){
    value = ( value + u[i] ) / 2;
  }
  
  cout << fixed << setprecision(10) << value << endl;
 
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
s = ["a"]
ord_a = ord("a")
ans = []
from copy import deepcopy
def dfs(s):
    if len(s) == n:
        ans.append("".join(s))
        return   
    max_ord = 0
    for i in s:
        max_ord = max(max_ord, ord(i) - ord_a)
    for j in range(max_ord + 2):
        new_s = deepcopy(s)
        new_s.append(chr(j + ord_a))
        dfs(new_s)
if n == 1:
    print("a")
    sys.exit()
dfs(s)
ans.sort()
for i in ans:
    print(i)
    







Measured memory_bytes: 72280
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
K = int(input())
RUN = {
    0:[0, 1],
    1:[0, 1, 2],
    2:[1, 2, 3],
    3:[2, 3, 4],
    4:[3, 4, 5],
    5:[4, 5, 6],
    6:[5, 6, 7],
    7:[6, 7, 8],
    8:[7, 8, 9],
    9:[8, 9]
}
cnt = 0

def dfs(i, s, p, cnt):
    if i == 0:
        if s == 0:
            return cnt        
        cnt += 1
        if cnt == K:
            print(s)
            exit()
        else:
            return cnt
    if s == 0:
        for ii in range(10):
            cnt = dfs(i-1, s+ii*10**(i-1), ii, cnt)
    else:
        for ii in RUN[p]:
            cnt = dfs(i-1, s+ii*10**(i-1), ii, cnt)

    return cnt

dfs(10, 0, 0, cnt)

Measured memory_bytes: 3064
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, a[3], ans = 0;
  scanf("%lld", &n);
  ll dp[n][3];
  for(i = 0; i < n; ++i) for(j = 0; j < 3; ++j) dp[i][j] = 0;
  for(i = 0; i < n; ++i) {
    for(j = 0; j < 3; ++j) scanf("%lld", &a[j]);
    if(i) {
      for(j = 0; j < 3; ++j) for(k = 0; k < 3; ++k) if(j != k && dp[i - 1][j] + a[k] > dp[i][k]) dp[i][k] = dp[i - 1][j] + a[k];
    } else for(j = 0; j < 3; ++j) dp[i][j] = a[j];
  }
  for(i = 0; i < 3; ++i) if(ans < dp[n - 1][i]) ans = dp[n - 1][i];
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<functional>
#include<deque>
#include<string.h>
#include<ctype.h>
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  if (a <= b){
    cout << a << endl;
  } else {
    cout << a-1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//size_t f = string::npos
//make pair, tuple

int s(string s1, string s2){
      if(s1.length() < s2.length())return 1;
      else if(s1.length() > s2.length())return 2;
      int n = s1.length();
      for(int i = 0;i < n;i++){
            if((int)s1[i] > (int)s2[i])return 2;
            else if((int)s1[i] < (int)s2[i])return 1;
      }
      return 3;
}

int main(){
      string a,b;cin >> a >> b;
      if(s(a, b) == 3)cout << "EQUAL";
      else if(s(a, b) == 1)cout << "LESS";
      else if(s(a, b) == 2)cout << "GREATER";
}

Measured memory_bytes: 256