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

using namespace std;

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

typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
const ll mod = 1e9+7;

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	ll n, a,b;
	cin >>n >>a >>b;
	if(b<a){ puts("0");return 0;}
	if(n==2){ puts("1");return 0;}
	//if(a==b){ cout << n <<"\n"; return 0;}
	if(n==1 && b!=a) { puts("0");return 0;}

	
	
	ll ans = b*(n-2)-a*(n-2)+1;
	
	cout << ans << "\n";
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

vector<pair<long long, int>> c_info;

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

	int N, M;
	cin >> N >> M;

	c_info.assign(N, make_pair(0, 0));
	for (int i = 0; i < N; i++)
	{
		cin >> c_info[i].first >> c_info[i].second;
	}

	sort(c_info.begin(), c_info.end());

	long long result = 0;

	int idx = 0;
	while (M > 0)
	{
		int buy_cnt = min(M, c_info[idx].second);
		M -= buy_cnt;

		result += buy_cnt * c_info[idx].first;
		idx++;
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 1792
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0
ansl = []
for t in T:
    l = 0
    r = n
    while l < r:
        i = (l + r)//2
#         print(l, i, r)
        if S[i] > t:
            r = i
        elif S[i] < t:
            l = i + 1
        else:
            ans += 1
            ansl.append(t)
            break
print(ans)


Measured memory_bytes: 16712
import sys
import numpy as np
TYPE_NUM = 26

def resolve():

    inp = sys.stdin.readlines()
    D = int(inp[0])
    c = np.array(list(map(int, inp[1].split(' '))))
    s = []
    last = np.zeros(TYPE_NUM, dtype=int)
    types = []

    for i in range(2, len(inp)):
        s.append(list(map(int, inp[i].split(' '))))
    s = np.array(s, dtype=int)

    for d in range(D):
        opt_delta_satis = -10 ** 32
        opt_idx = 0
        for idx in range(TYPE_NUM):
            val = s[d, idx]
            org = last[idx]
            last[idx] = d+1
            temp_delta_satis = np.sum(-c*(d+1-last)) + val
            if opt_delta_satis < temp_delta_satis:
                opt_delta_satis = temp_delta_satis
                opt_idx = idx
            last[idx] = org
        types.append(opt_idx+1)
    print(*types, sep='\n')

resolve()

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

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

    int N;
    cin >> N;
    vector<int> X(N);
    for (auto &x : X) cin >> x;
    vector<int> XX = X;
    sort(XX.begin(), XX.end());
    int L = XX.at(N / 2 - 1);
    int R = XX.at(N / 2);

    for (auto &x : X) {
        if (x <= L) {
            cout << R << endl;
        } else {
            cout << L << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3840
import bisect

n = int(input())
a = list(map(int, input().split()))
b = [abs(i) for i in a]
a.sort()
if a[0] >= 0:
    print(sum(a[1:])-a[0])
    if n == 2:
        print(a[1],a[0])
    else:
        now = a[0]
        for i in range(n-2):
            print(now,a[i+1])
            now -= a[i+1]
        print(a[-1],now)
            
elif a[-1] <= 0:
    print(a[-1]-sum(a[:-1]))
    now = a[-1]
    for i in range(n-1):
        print(now, a[i])
        now -= a[i]
else:
    print(sum(b))
    zero = bisect.bisect_left(a,0)
    now1 = a[-1]
    now2 = a[0]
    for i in range(zero-1):
        print(now1,a[i+1])
        now1 -= a[i+1]
    for j in range(n-zero-1):
        print(now2,a[-(j+2)])
        now2 -= a[-(j+2)]
    print(now1,now2)
        

Measured memory_bytes: 15800
H,W = map(int,input().split(' '))
N = [[i for i in input()] for i in range(H)]
lst = [-1,0,1]
for i in range(H):
    for x in range(W):
        if N[i][x] == '.':
            ans = 0
            for i1 in lst:
                for x1 in lst:
                    if (i+i1 >= 0 and x+x1 >= 0) and (i+i1 < H and x+x1 < W):
                        if N[i+i1][x+x1] == "#":
                            ans = ans + 1
            N[i][x] = ans

[print(''.join([str(x) for x in i])) for i in N]


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  ll k;
  cin >> k;
  ll N = 50;
  ll d = k / N;
  ll n = k % N;

  vector<ll> a(N);
  REP(i, N) { a[i] = i + d; }
  REP(i, n) {
    a[i] += N;
    REP(j, N) {
      if (j == i)
        continue;
      a[j]--;
    }
  }

  cout << N << endl;
  REP(i, N) {
    cout << a[i] << " ";
    if (i == N - 1)
      cout << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

    if(abs(a-b) > abs(a-c)){
        if(abs(a-c) <= d) puts("Yes");
        else puts("No");
    }else {
        if(abs(a-b) <= d && abs(b-c) <= d) puts("Yes");
        else puts("No");
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
	string N;
	cin >> N;
	int num = atoi(N.c_str());
	int sum = 0;
	for (int i = 0; i < (int)N.size(); ++i)
	{
		sum += (int)N[i] - (int)'0';
	}
	if(num % sum == 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int h,n,x;
long long sum;
int a[200005];
int main(){
	cin>>h>>n;
	for(int i=1;i<=h;++i)
		cin>>a[i];
	sort(a+1,a+h+1);
	for(int i=1;i<=h-n;++i)
		sum+=a[i];
	cout<<sum<<endl;
}

Measured memory_bytes: 1024
/*
 *  AUTHOR : MANAV PATEl
*/
#include<bits/stdc++.h>
#include<functional>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

namespace fastio {

	template <class T> istream &operator>>(istream &os, vector<T> & vec) {
		for (auto &u : vec)os >> u;
		return os;
	}
	template <class T> ostream &operator<<(ostream &os, const vector<T> & vec) {
		for (auto &u : vec)os << u << " ";
		return os;
	}
	template<class T1, class T2> inline istream& operator>>(istream& os, pair<T1, T2>& p) {
		return os >> p.first >> p.second;
	}
	template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
		return os << p.first << " " << p.second;
	}
	template <class T> ostream &operator<<(ostream &os, set<T> & con) {
		for (auto &u : con) os << u << " ";
		return os;
	}
	void re() {}
	template <typename T, typename... args> void re(T& x, args&... tail) {
		cin >> x;
		re(tail...);
	}
	void pr() {}
	template <typename T> void pr(const T& x) {
		cout << x;
	}
	template <typename T, typename... args> void pr(const T& x, const args&... tail) {
		cout << x << " ";
		pr(tail...);
	}
	template <typename... args> void prln(const args&... tail) {
		pr(tail...);
		cout << "\n";
	}
}
using namespace fastio;

typedef long long int ll;
typedef long double ld;

const ll mod = 1e9+7;
const ll mod1 = 998244353;

#define fill(a)  memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back

ll dp0[2005][2005];
ll dp1[2005][2005];

int main()
{
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	int n, m;
    cin >> n >> m;
    vector<int> s(n+2, -1), t(m+2, -2);
    for(int i = 0; i < n; ++i){
        cin >> s[i];
    }
    for(int i = 0; i < m; ++i){
        cin >> t[i];
    }
    dp0[0][0] = 1;
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= m; ++j){
            dp0[i+1][j] = (dp0[i+1][j] + dp0[i][j]) % mod;
            dp1[i][j] = (dp1[i][j] + dp0[i][j]) % mod;
            dp1[i][j+1] = (dp1[i][j+1] + dp1[i][j]) % mod;
            if(s[i] == t[j]){
                dp0[i+1][j+1] = (dp0[i+1][j+1] + dp1[i][j]) % mod;
            }
        }
    }
    cout << dp1[n][m] << endl;
}


Measured memory_bytes: 63104
import math
from collections import defaultdict
from itertools import accumulate
N=int(input())
data=defaultdict(int)
result=0
for i in range(2,int(math.sqrt(N))+1):
    while N%i==0:
        N//=i
        data[i]+=1
if N!=1:
    data[N]+=1
cumsum=list(accumulate(range(1,10**6*2)))
for value in data.values():
    for i in range(10**6*2):
        if value<cumsum[i]:
            result+=i
            break
if result==0:
    if N!=1:
        result=1
print(result)

Measured memory_bytes: 119372
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
ll a,b,ans;
int main()
{
	int i,j;
	scanf("%lld",&a);
	ans=9999999999999;
	int t=sqrt(a)+1;
	for(i=1;i<=t;i++)
	{
		if(a%i==0)
		{
			b=a/i;
			ans=min(ans,i-1+b-1);
		}
	}
	printf("%lld\n",ans);
//	for(i=1;i<=9;i++)
//	{
//		if(a%i==0)
//		{
//			b=a/i;
//			if(0<=b&&b<=9)
//			{
//				printf("Yes\n");
//				return 0;
//			}
//		}
//	} 
//    printf("No\n");
//	if(a<=9&&b<=9) printf("%d\n",a*b);
//	else printf("-1\n");
	return 0;
}

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

#define int long long

int N;
set< vector<int> > s;

signed main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        vector<int> in(3);
        for (int j = 0; j < 3; j++) cin >> in[j];
        sort(in.begin(), in.end());
        s.insert(in);
    }
    printf("%lld\n", N - s.size());
    return 0;
}

Measured memory_bytes: 3320
import scala.io.StdIn.{readInt,readLine}

object Main {
  def swap(a:Array[Int], i:Int, j:Int) = {
    val temp = a(i)
    a(i) = a(j)
    a(j) = temp
  }

  def canDraw(str:String, i:Int):Boolean =
    if( str.length==1 || (i==0 && str.length > 1 && str(i+1)!='1') || (i>0 && i==str.length-1 && str(i-1)!='1') ||
      (i>0 && i<str.length-1 && str(i+1)!='1' && str(i-1)!='1') ) true
    else false

  def scan(l:Array[Int], m:Int, x:Int, d:Int, s:Array[String],line:Int,pos:Int):String = {
    if(line == d) "1"
    else {
      val lots = l.clone
      var result = ""
      if(line == -1) {
        for(i<-0 until d) {
          for(j<-0 until s(i).length)
            if(s(i)(j)=='1') swap(lots,j,j+1)
        }
        if(lots(x-1) == m) result ="0"
      } else if(canDraw(s(line),pos) ) {
        for(i<-0 until d) {
          for(j<-0 until s(i).length) {
            if(s(i)(j)=='1') {
              swap(lots,j,j+1)
            } else {
              if(line==i && j==pos) {
                swap(lots,j,j+1)
              }
            }
          }
        }
        if(lots(x-1) == m) result = (line+1) + " " + (pos+1)
      }

      if(result == "") {
        if(pos >= s(0).length-1) scan(l,m,x,d,s,line+1,0)
        else scan(l,m,x,d,s,line,pos+1)
      } else {
        result
      }
    }
  }

  def main(args:Array[String]) = {
    Iterator.continually(readLine).takeWhile(_.trim!="0").foreach { s =>
      val n = s.toInt
      val (m,x,d) = (readLine.trim.toInt,readLine.trim.toInt,readLine.trim.toInt)
      val lots = (1 to n).toArray

      val list = for(i<-1 to d) yield readLine.trim
      println(scan(lots,m,x,d,list.toArray,-1, 0))
    }
  }
}

Measured memory_bytes: 45108
// AOJ DSL_2_B Range Sum Query
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

// intersects returns whether [a1, b1) \cap [a2, b2) is nonempty
bool intersects(int a1, int b1, int a2, int b2) {
  return ((a2 >= a1 and a2 < b1) or (a1 >= a2 and a1 < b2));
}

struct Seg {
  int start;
  int end;
  int x;
  Seg *l;
  Seg *r;
  Seg(int start, int end, int x) : start(start), end(end), x(x) {
    if (end > start + 1) {
      l = new Seg(start, (start + end) / 2, x);
      r = new Seg((start + end) / 2, end, x);
    }
  }
  int Get(int s, int t) {
    if (s <= start and t >= end) {
      return x;
    } else if (intersects(s, t, l->start, l->end) and
               intersects(s, t, r->start, r->end)) {
      return l->Get(s, t) + r->Get(s, t);
    } else if (intersects(s, t, l->start, l->end)) {
      return l->Get(s, t);
    } else { // intersects right interval
      return r->Get(s, t);
    }
  }
  void Add(int i, int addend) { // 1-indexed
    if (start == end - 1) {
      x += addend;
      return;
    }
    ((i < l->end) ? l : r)->Add(i, addend);
    x = l->x + r->x;
  }
};

int main() { // 1-indexing
  int n, q;
  cin >> n >> q;
  auto seg = new Seg(1, n + 1, 0);
  int c, x, y;
  while (cin >> c >> x >> y) {
    if (c == 0)
      seg->Add(x, y); // internal repr. is 1-indexed
    if (c == 1)
      cout << seg->Get(x, y + 1) << endl; // and uses open intervals
  }
}


Measured memory_bytes: 12468
//
//  arc103a.cpp
//  
//
//  Created by Yoshida Satoshi on 2018/10/23.
//

#include <stdio.h>
#include <iostream>
#include <cmath>

using namespace std;;

int main(){
    int n;
    int v[100005];
    int a[100005]={};
    int b[100005]={};
    
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    
    for(int i=0;i<n;i++){
        if(i%2==0) a[v[i]]++;
        else       b[v[i]]++;
    }
    
    int a1,a2,b1,b2;
    int va1,va2,vb1,vb2;
    
    a1=a2=b1=b2=0;
    va1=va2=vb1=vb2=0;
    
    for(int i=1;i<=100000;i++){
        if(a[i]>=va1){
            a2=a1;va2=va1;
            a1=i;va1=a[i];
        }
        else if(a[i]>=va2){
            a2=i;va2=a[i];
        }
        
        if(b[i]>=vb1){
            b2=b1;vb2=vb1;
            b1=i;vb1=b[i];
        }
        else if(b[i]>=vb2){
            b2=i;vb2=b[i];
        }
    }
    
    int ans=n;
    
    if(a1!=b1){
        ans-=(va1+vb1);
    }
    else{
        ans-=max(va1+vb2,va2+vb1);
    }
    
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 1408
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

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

void test() {
    int n, m, x;
    cin >> n >> m >> x;
    int c[n], a[n][m];
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }
    int ans = INT_MAX;
    for (int i = 0; i < (1 << n); ++i) {
        int cur = 0, cnt[m] = {0};
        for (int j = 0; j < n; ++j) {
            if (i & (1 << j)) {
                cur += c[j];
                for (int u = 0; u < m; ++u) {
                    cnt[u] += a[j][u];
                }
            }
        }
        bool ok = true;
        for (int i = 0; i < m; ++i) {
            if (cnt[i] < x) {
                ok = false;
                break;
            }
        }
        if (ok) ans = min(ans, cur);
    }
    if (ans == INT_MAX) {
        cout << "-1\n";
        return;
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef HOME
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin >> t;
    for (int i = 0; i < t; ++i) {
        test();
    }
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e7;  
using  p = pair<int,int>;
int n,m;
auto c = vector<vector<int> >();

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

   auto d=0;
   for (int i = 0; i <= a; i++)
   {
      for (int j = 0; j <= b; j++)
      {   
         for (int k = 0; k <= c; k++)
         {
            if(x==i*500+j*100+k*50)d++;
         }
      }
   }
   
   cout << d;
   
}
  
  

Measured memory_bytes: 256
N, M = map(int, input().split())
cand = ['*'] * N
mn = ''
for m in range(M):
    s, c = map(int, input().split())
    if s==1 and c==0 and N > 1:
        mn = '-1'

    if cand[s-1] == '*' or cand[s-1] == str(c):
        cand[s-1] = str(c)
    else:
        mn = '-1'
if mn == '-1':
    print (mn)
    exit()

for i in range(N):
    if cand[i]=='*':
        if i==0 and N > 1:
            mn+='1'
        else:
            mn+='0'
    else:
        mn+=cand[i]
print (mn)

Measured memory_bytes: 3064
MAX = 10 ** 18

N, *A = map(int, open(0).read().split())

if 0 in A:
    print(0)
    quit()

ans = 1
for a in A:
    if ans > MAX:
        print(-1)
        quit()
    ans *= a


if ans > MAX:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 21664
#include <bits/stdc++.h>
#define S second
#define F first
#define ll long long

using namespace std;

const ll N = 105;

int n, c[N][12];

vector<int> p[10];
vector<int> temp = vector<int>(n, 0);

int main()
{
    scanf("%d", &n);
    int xx;
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < 10 ; j++)
        {
            scanf("%d", &xx);
            if(xx) p[j].emplace_back(i);
        }
    }
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j <= 10 ; j++)
        {
            scanf("%d", c[i] + j);
        }
    }
    ll mx = -1e18, ans = 0;
    for(int i = 1 ; i < 1024 ; i++)
    {
        ans = 0;
        temp = vector<int> (n, 0);
        for(int j = 0 ; j < 10 ; j++)
        {
            if((i>>j) & 1)
            {
                for(auto k:p[j]) temp[k]++;
            }
        }
        for(int ii = 0 ; ii < temp.size() ; ii++) ans += c[ii][temp[ii]];
        mx = max(mx, ans);
    }
    printf("%lld\n", mx);
    return 0;
}


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

using namespace std;
typedef long long ll;

ll by_bit_brute_force(const string &s)
{
    int n = s.size()-1;
    ll ans = 0, k = 1, sum;
    for(int i=0; i < (1 << n); ++i){
        sum = 0;
        k = 1;
        for(int j=0;j<n;++j){
            if((i >> j) & 1){
                ans += (s[n-j] - '0') * k;
                k = 1;
            }
            else{
                ans += (s[n-j] - '0') * k;
                k *= 10;
            }
        }
        ans += (s[0] - '0') * k;
    }
    return ans;
}

ll dfs(string s, int index, ll sum, ll k)
{
    if(index == 0){
        return k * (s[index] - '0') + sum;
    };
    sum += (s[index] - '0') * k;
    return dfs(s, index-1, sum, k*10) + dfs(s, index-1, sum, 1);
}

int main()
{
    string s;
    cin >> s;
    cout << by_bit_brute_force(s) << endl;
    //cout << dfs(s, s.size()-1, 0, 1) << endl;
}


Measured memory_bytes: 256
# 参考： https://atcoder.jp/contests/abc088/submissions/10507715
H, W = gets.chomp.split.map(&:to_i)
MAP = readlines.map { |line| line.chomp.chars }

G = [W - 1, H - 1]
routes = []
queues = [[[0, 0], [[0, 0]]]]
MAP[0][0] = 'x'

DIRS = [[1, 0], [-1, 0], [0, 1], [0, -1]]
goal = false

def get(x, y)
  if 0 <= x && x < W && 0 <= y && y < H
    MAP[y][x]
  else
    nil
  end
end

while !queues.empty?
  pos, routes = queues.shift

  if pos[0] == G[0] && pos[1] == G[1]
    goal = true
    break
  end

  case get(pos[0], pos[1])
  when '#', nil
    next
  else
    DIRS.each do |dx, dy|
      x = pos[0] + dx
      y = pos[1] + dy
      nn = get(x, y)
      if nn == '.'
        MAP[y][x] = 'x'
        queues.push([[x, y], routes + [[x, y]]])
      end
    end
  end
end

unless goal
  p -1
  exit
end

routes.each do |x, y|
  MAP[y][x] = 'o'
end
score = 0
H.times do |h|
  W.times do |w|
    score += 1 if MAP[h][w] == '.' || MAP[h][w] == 'x'
  end
end
p score

Measured memory_bytes: 2556
n, m = map(int, input().split())
L = [list(input().split()) for _ in range(m)]

AC, WA = [0] * n, [0] * n

ac, wa = 'AC', 'WA'

for i in range(m):
    if L[i][1] == ac and AC[int(L[i][0]) - 1] == 0:
        AC[int(L[i][0]) - 1] = 1
    elif L[i][1] == wa and AC[int(L[i][0]) - 1] == 0:
        WA[int(L[i][0]) - 1] += 1
sum_ac, sum_wa = 0, 0
for i in range(n):
    sum_ac += AC[i]
    if AC[i] > 0:
        sum_wa += WA[i]
print(sum_ac, end = ' ')
print(sum_wa)

Measured memory_bytes: 27464
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    double x1,x2,x3,y1,y2,y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    double l1,l2,l3;
    l1 = sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
    l2 = sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
    l3 = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    if(l2 < l3)swap(l2, l3);
    if(l1 < l2)swap(l1, l2);

    double s_ = (l1+l2+l3)/2;
    double s = sqrt(s_ * (s_ - l1) * (s_ - l2) * (s_ - l3));
    double h = 2 * s / l1;

    double r = s / (s_ + h);
    cout << fixed << setprecision(10) << r << endl; // 10桁表示
    return 0;
}
 
 


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <numeric>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
/*
bool ok(vector<int>& L, int X){
  int idx = L.size();
  int first = 0;
  while(true){
    int cnt = 1;
    int now = first;
    bool ok = true;
    REP(i, idx){
      if(now + L[i] <= X){
        now += L[i];
      }else{
        now = L[i];
        cnt++;
      }
      if(cnt > M || now > X){
        ok = false;
        break;
      }
    }
    if(ok) return true;

    idx--;
    assert(idx >= 0);
    first += L[idx];
    if(first > X) break;
  }
  return false;
}
*/
int N, M;
vector<int> L;
bool ok(int X){
  int firstsum = 0; // add L[0], L[1], ..., L[b - 1] to last block
  for(int b = 0; b < N; b++){ // begin index of first block
    if(firstsum > X) break;
    int rest = M; // rest of blocks
    int partial = 0; // sum of current block
    for(int i = b; i < N; i++){
      partial += L[i];
      if(partial > X){ // use next block
        partial = L[i];
        rest --;
        if(rest <= 0) break; // block shortage
      }
    }
    //printf("rest = %d partial = %d firstsum = %d X = %d\n", rest, partial, firstsum, X);
    if(rest > 0 && partial + firstsum <= X) return true; // last block is not overflow

    firstsum += L[b]; // add L[b] to last block
  }
  return false;
}

int main(){
  while(cin>>N>>M && N){
    L.assign(N, 0);
    REP(i, N) scanf("%d", &L[i]);
    int S = accumulate(L.begin(), L.end(), 0);
    int lb = ceil(double(S) / M) - 1; // answer >= ceil(S / M)
    REP(i, N) lb = max(lb, L[i] - 1); // answer >= max(L[i])
    int ub = S; // answer <= S
    while(ub - lb > 1){
      int mid = (ub + lb) / 2;
      if(ok(mid)){
        ub = mid;
      }else{
        lb = mid;
      }
    }
    cout<<ub<<endl;
  }
  return 0;
}

Measured memory_bytes: 1288
import sys
N = int(sys.stdin.readline())
A = [list(map(int, sys.stdin.readline().split())) for i in range(2)]
ans = 0
for i in range(N):
    x, y = 0, 0
    turn = 0
    sum = 0
    while turn <= N:
        sum = sum + A[x][y]
        if turn == i:
            x = 1
        else:
            y += 1
        turn += 1
    ans = max(ans, sum)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
constexpr lnt INF = 2e18;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

int main() {
	int n;
	std::cin >> n;
	int N=1e6+1;
	std::vector<int> a(n);
	std::vector<int> v(N,0);
	rep(i,n) std::cin >> a[i];
	rep(i,n) v[a[i]]++;
	for(int i=1;i<N;i++) {
		if(v[i]==0) continue;
		for(int j=2;i*j<N;j++) {
			v[i*j]=0;
		}
	}
	int count=0;
	rep(i,n) if(v[a[i]]==1) count++;
	print(count);
}


Measured memory_bytes: 7920
#include<iostream>
#include<cmath>
#include <stdlib.h>
#include<stdio.h>

using namespace std;


int main(){
	long int n,m,p[200000],sum=0,max=0;
	cin >> n >> m ;
	for(int i=0;i<n;i++){
		cin >> p[i];
	}
	for(int i=0;i<m;i++){
		sum+=p[i];
	}
	max = sum;
	for(int i=m;i<n;i++){
		sum=sum-p[i-m]+p[i];
		if(sum>max)max=sum;
	}
	printf("%lf\n",(double)(max+m)/2);
	return 0;
}

Measured memory_bytes: 1792
def bitadd(a,w,bit): #aにwを加える(1-origin)
 
    x = a
    while x <= (len(bit)-1):
        bit[x] += w
        x += x & (-1 * x)
 
def bitsum(a,bit): #ind 1～aまでの和を求める
 
    ret = 0
    x = a
    while x > 0:
        ret += bit[x]
        x -= x & (-1 * x)
    return ret

from sys import stdin
N,Q = map(int,stdin.readline().split())

c = list(map(int,stdin.readline().split()))
last = [1] * (N+1)

li = [ [] for i in range(N+2)]
ans = [None] * Q
for i in range(Q):
    L,R = map(int,stdin.readline().split())
    L += 1
    R += 1
    li[R].append((L,i))

BIT = [0] * (N+2)
bitadd(1,N,BIT)

for i in range(N):

    nc = c[i]
    lastind = last[nc]
    last[nc] = i+2

    bitadd(lastind,-1,BIT)
    bitadd(i+2,1,BIT)

    for l,qind in li[i+2]:
        ans[qind] = bitsum(i+2,BIT) - bitsum(l-1,BIT)

print (*ans)



Measured memory_bytes: 198976
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define eps 1e-8
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    int a,b;cin>>a>>b;
    int ans=(a-2*b);
    if(ans<0)ans=0;
    cout<<ans;
}

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

int main()
{
	string s;
	cin >> s;
	if(s[0]==s[1] && s[1]==s[2] && s[0]==s[2])
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<math.h> 
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#define max(a,b) (a>b ? a : b)
#define min(a,b) (a<b ? a : b)
using namespace std;
typedef long long int lli;
lli mod=1000000007;
vector < lli> primes;

void Sieve(lli n) 
{ 
    bool prime[n+1];
	for(lli i=0;i<n+1;++i)
		prime[i]=true;
    for (lli p=2;p*p<=n;++p) 
    {
        if (prime[p] == true) 
        {  
            for (lli i=2*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    }  
    for(lli p=2; p<=n; p++) 
       if (prime[p]) 
		primes.push_back(p);  
}
lli gcd(lli a,lli b)  
 {
    if(b>a)
        swap(a,b);
    if (a%b==0)  
        return b;  
    else 
        return gcd(a%b,b);  
 }
lli lcm(lli a,lli b)
{
    return (a*b)/gcd(a,b);    
}
lli power(lli x,lli y,lli m)   
{ 
    lli res = 1; 
    x=x%m;   
    while (y > 0) 
    {  
        if (y%2==1) 
            res =(res*x)%m;  
        y=y/2; 
        x=(x*x)%m; 
    } 
    return res; 
}
bool sortcol( const vector<lli>& v1, const vector<lli>& v2 ) 
{ 
	return v1[0] < v2[0]; 
}
int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	lli n;
	cin>>n;
	lli curr=10;
	lli add=9;
	lli ans=0;
	while(curr<=n)
	{
		ans+=add;
		curr*=100;
		add*=100;
	}
	curr/=10;
	if(curr<=n)
	    ans+=(n-curr+1);
	cout<<ans<<endl;
	
}

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

int main() {
  int N, K; cin >> N >> K;    
  vector<int> l(N);
  int ret = 0;

  for (int i = 0; i < N; ++i) cin >> l[i];

   sort(l.begin(), l.end(), greater<int>());

  for (int i = 0; i < K; ++i) ret += l[i];
  cout << ret << endl;
  return (0);
}

Measured memory_bytes: 3600
#include<iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	bool isodd = false;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x % 2 == 1) {
			isodd = !isodd;
		}
	}
	if (isodd) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int W,H,x,y,r;
	
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	
	if(W>=x+r&&H>=y+r&&0<=x-r&&0<=y-r){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2148
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-12;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	vector<int>w(N);
	for (auto &i : w)cin >> i;
	vector<vector<int>>dp(1 << N, vector<int>(N, MOD));
	vector<vector<int>>add(1 << N, vector<int>(N, 0));
	for (int i = 0; i < 1<<N; i++) {
		for (int j = 0; j < N; j++) {
			if ((i >> j) & 1)continue;
			for (int k = j + 1; k < N; k++) {
				if ((i >> k) & 1)add[i][j]++;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		dp[1 << i][i] = 0;
	}
	for (int i = 0; i < 1 << N; i++) {
		int used = 0;
		for (int j = 0; j < N; j++) {
			if ((i >> j) & 1)used++;
		}
		for (int j = 0; j < N; j++) {
			if (dp[i][j] == MOD)continue;
			int bef = 0;
			if (used % 2 != j % 2)bef = v[j];
			else bef = w[j];
			for (int k = 0; k < N; k++) {
				if ((i >> k) & 1)continue;
				int c = 0;
				if (used % 2 == k % 2)c = v[k];
				else c = w[k];
				if (bef > c)continue;
				dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] + add[i][k]);
			}
		}
	}
	int ans = MOD;
	for (auto i : dp.back())ans = min(ans, i);
	if (ans == MOD)ans = -1;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 55552
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func Solve(stdin io.Reader, stdout io.Writer) {
	sc := bufio.NewScanner(stdin)

	/* 入力バッファが大きくなるならこれ */
	buf := make([]byte, 10000000)
	sc.Buffer(buf, 10000000)

	sc.Scan()
	b := sc.Text()

	if b[0] == 'A' {
		_, _ = fmt.Fprintf(stdout, "T\n")
	} else if b[0] == 'T' {
		_, _ = fmt.Fprintf(stdout, "A\n")
	} else if b[0] == 'C' {
		_, _ = fmt.Fprintf(stdout, "G\n")
	} else {
		_, _ = fmt.Fprintf(stdout, "C\n")
	}
}

func main() {
	Solve(os.Stdin, os.Stdout)
	return
}

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

int main() {
  ll n;
  cin >> n;
  vector<pair<ll,ll>> a(n);
  rep(i,n){
    int x;
    cin >> x;
    a[i] = make_pair(x,i+1);
  }
  
  sort(a.begin(),a.end());
  
  for(auto s : a){
    cout << s.second << " ";
  }
  cout << endl;
  
  return(0);
}

Measured memory_bytes: 4772
import java.util.*
import java.math.*

fun main(args: Array<String>) {
    var (N, K) = readLine()!!.split(" ").map { it.toInt() }
//    var N = readLine()!!.toInt()
//    val S = readLine()!!
//    val D = readLine()!!.split(" ").map { it.toLong() }

    println((N*3+K)/2)
}


Measured memory_bytes: 37744
#include <bits/stdc++.h>
// atoi : atoi(変数名.c_str())
// find(): int i = 変数名.find(“文字列”) 何番目にあるかを得る
// cout << (条件 ? "Yes" : "No") << endl;
// 降順 sort(a.begin(),a.end(),greater<int>());
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int n;
  cin >> n;
  set<int> s;
  int ans = 0;
  rep(i,n){
    int tmp;
    cin >> tmp;
    if(s.count(tmp)) continue;
    s.insert(tmp);
    ans++;
  }
  cout << (ans % 2 == 1 ? ans : ans-1) << endl;
}


Measured memory_bytes: 4992
n=int(input())
list=[input() for i in range(n)]
ans_AC=len([1 for x in list if x=="AC"])
ans_WA=len([1 for x in list if x=="WA"])
ans_TLE=len([1 for x in list if x=="TLE"])
ans_RE=len([1 for x in list if x=="RE"])
print("AC x "+str(ans_AC))
print("WA x "+str(ans_WA))
print("TLE x "+str(ans_TLE))
print("RE x "+str(ans_RE))

Measured memory_bytes: 16832
from collections import deque

N = int(input())

D = deque(['1','2','3','4','5','6','7','8','9'])
if N < 10:
  print(list(D)[N-1])
else:
  cnt = 9
  while cnt < N:
    a = D.popleft()
    for k in range(-1, 2):
      _plus = int(a[-1]) + k
      if not(_plus >= 0 and _plus <= 9):
        continue
      u = a + str(_plus)
      D.append(u)
      cnt +=1
      #print(cnt, u)
      if cnt == N:
        print(u)
        break
    else:
      continue
    break

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    int a, b, c; cin >> a >> b >> c;
    int ma = max( { a, b, c } );

    int ans = 0;
    while( ma - a > 1 ){
        a += 2;
        ans++;
    }

    while( ma - b > 1 ){
        b += 2;
        ans++;
    }

    while( ma - c > 1 ){
        c += 2;
        ans++;
    }

    int same = 0;
    if( ma == a ) same++;
    if( ma == b ) same++;
    if( ma == c ) same++;

    if( same == 1 ){
        cout << ans + 1 << endl;
    }else if( same == 2 ){
        cout << ans + 2 << endl;
    }else{
        cout << ans << endl;
    }

}


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

using namespace std;

int main(){
	int N;
	int M;
	int X;
	int Y;

	cin >> N >> M >> X >> Y;
	vector<int> X_city(N+1, X);
	vector<int> Y_city(M+1, Y);

	for (int n=0; n<N; n++){
		cin >> X_city[n+1];
	}

	for (int m=0; m<M; m++){
		cin >> Y_city[m+1];
	}

	int X_max;
	int Y_min;

	X_max = *max_element(X_city.begin(), X_city.end());
	Y_min = *min_element(Y_city.begin(), Y_city.end());

	//cout << X_max << endl;
	//cout << Y_min << endl;

	if (X_max < Y_min){
		cout << "No War" << endl;
	}
	else{
		cout << "War" << endl;
	}
}

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

using namespace std;


const int max_a = 100000;

int main() {
	int a[max_a];
	int a_count[max_a] = {};
	int n;
	cin >> n;

	int max_val = -1;
	int min_val = max_a + 1;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		max_val = max(a[i], max_val);
		min_val = min(a[i], min_val);
		a_count[a[i]] ++;
	}

	if (max_val - min_val > 1) {
		cout << "No" << endl;
		return 0;
	}


	if (min_val == max_val) {
		if (max_val == n - 1 || max_val == 1) {
			cout << "Yes" << endl;
			return 0;
		}

		if (2 <= max_val && max_val <= n / 2) {
			cout << "Yes" << endl;
			return 0;

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



	}

	//cout << "OK1" << endl; 

	int kind_count = a_count[min_val];

	int max_make_with_max = a_count[max_val] / 2;

	//cout << "kind_count:" << kind_count << " max_make_with_max:" << max_make_with_max << endl; 
	//cout << "max_val:" << max_val << " min_val:" << min_val << endl; 


	if (kind_count + 1 <= max_val && max_val <= kind_count + max_make_with_max) {
		cout << "Yes" << endl;
		return 0;
	}


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

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

map<vi, int> perm;
void dfs(int t, int d=0, vi v={}, set<int> p={})
{
    if ((int)(v.size()) == t) {
        perm[v] = perm.size();
        return;
    }
    rep1(j, t) {
        if (p.find(j)==p.end()) {
            vi pv = v; set<int> pp = p;
            pv.push_back(j);
            pp.insert(j);
            dfs(t, d+1, pv, pp);
        }
    }
}

int main(){
    int n;
    cin >> n;
    vi p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    dfs(n);
    cout << abs(perm[p]-perm[q]) << endl;
    return 0;
}


Measured memory_bytes: 5248
#include<iostream>
#include<string>
#include<map>
#include<sstream>
#include<cctype>
#include<algorithm>
using namespace std;
typedef string::const_iterator Cursol;
bool ok;
int bit;
bool Formula(Cursol &c){
  bool ret;
  char z = *c++;

  if(z == 'T'){
    ret = true;
  }else if(z == 'F'){
    ret = false;
  }else if(islower(z)){
    ret = bit >> ((z) - 'a') & 1;
  }else if(z == '-'){
    return !Formula(c);
  }else if(z == '('){
    ret = Formula(c);
    z = *c++;
    if(z == '+'){
      ret |= Formula(c);
    }else if(z == '*'){
      ret &= Formula(c);
    }else if(z == '-'){ //->
      c++;
      ret = !ret | Formula(c);
    }
    c++;
  }
  // cout << ret << endl;
  return ret;
}
int main(){
  string s;
  Cursol c;
  while(cin >> s , ok = true, s != "#"){
    string l = s.substr(0,s.find('='));
    string r = s.substr(s.find('=')+1);

    for(bit = 0 ; bit < (1 << 11) ; bit++ ){
      c = l.begin();
      bool java = Formula(c);
      c = r.begin();
      if( java != Formula(c) ){
	ok = false;
	break;
      }
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 1236
# include "stdio.h"

int main(){
    char s[11],a[11];
    scanf("%s",s);
    int c=0;
    for(int i=0;i<11;i++)
        a[i]='\0';
    for(int i=0;i<10;i++){
        if(s[i]!='B'){
            a[c]=s[i];
            c++;
        }else{
            if(c!=0) c--;
            a[c]='\0';
        }
    }
    printf("%s\n",a);




}


Measured memory_bytes: 128
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define pb(x)                       push_back(x)
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const int MAXN = 3e3 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

string s, t;
ll ss, ts;

ll dp[MAXN][MAXN];
pii par[MAXN][MAXN];
char ans[MAXN][MAXN];


int main()
{
    fast_io;
    cin >> s >> t;
    ss = s.size();
    ts = t.size();
    for (int i = 1;i <= ss;i++){
        for (int j = 1; j <= ts;j++){
            if (s[i - 1] == t[j - 1]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
                par[i][j] = {i - 1,j - 1};
                ans[i][j] = s[i - 1];
            }
            else{
                dp[i][j] = max(dp[i - 1][j],dp[i][j - 1]);
                if (dp[i][j] == dp[i - 1][j]){
                    par[i][j] = {i - 1,j};
                    ans[i][j] = '?';
                }
                else{
                    par[i][j] = {i,j - 1};
                    ans[i][j] = '?';
                }
            }
        }
    }
    string res = "";
    ll k = ss;
    ll o = ts;

    ll tmp;
    while(k != 0 and o != 0){
        //cout << k << tab << o << endl;
        if (ans[k][o] != '?'){
            res = ans[k][o] + res;
        }
        tmp = par[k][o].F;
        o = par[k][o].S;
        k = tmp;
    }
    //cout << dp[ss][ts] << endl;
    cout << res << endl;
}


Measured memory_bytes: 150528
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef struct node_{
    int key;
    int x[2];
    struct node_ *left;
    struct node_ *right;
}node;

vector<node> V;
vector<int> ans;

bool ascX(const node& left, const node& right){
    return left.x[0] != right.x[0] ? left.x[0] < right.x[0] : left.x[1] < right.x[1];
}

bool ascY(const node& left, const node& right){
    return left.x[1] != right.x[1] ? left.x[1] < right.x[1] : left.x[0] < right.x[0];
}

bool (*asc[2])(const node& left, const node& right) = {ascX,ascY,};

node *make2Dtree(int left, int right, char d){
    if(left>=right){
        return NULL;
    }
    int mid = (left + right)/2;
    sort(V.begin()+left, V.begin()+right, asc[d]);
    node *p = &V[mid];
    p->left = make2Dtree(left, mid, (d+1)%2);
    p->right = make2Dtree(mid+1, right, (d+1)%2);
    return p;
}

void find(node *root, int *sx, int *tx, char d){
    if(root==NULL)return;
    int x[2] = {root->x[0], root->x[1],};

    if(sx[0] <= x[0] && x[0] <= tx[0] && sx[1] <= x[1] && x[1] <= tx[1])ans.push_back(root->key);

    if(sx[d] <= x[d])find(root->left, sx, tx, (d+1)%2);
    if(x[d] <= tx[d])find(root->right, sx, tx, (d+1)%2);
}

int main(){
    int i,j,n,q,x,y,sx[2],tx[2];
    node tmp;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&x,&y);
        tmp.key = i;
        tmp.x[0] = x;
        tmp.x[1] = y;
        V.push_back(tmp);
    }
    node* root;
    root = make2Dtree(0, n, 0);

    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d %d %d %d",sx,tx,sx+1,tx+1);
        ans.clear();
        find(root,sx,tx,0);
        sort(ans.begin(), ans.end());
        for(j=0;j<ans.size();j++)printf("%d\n",ans[j]);
        printf("\n");
    }

    return 0;
}



Measured memory_bytes: 18824
fun main(args: Array<String>) {
    val k = readLine()!!.toInt()
    val input = readLine()!!.split(" ").map(String::toInt)
    val a = input[0]
    val b = input[1]

    var answer = "NG"
    for (i in a..b) if (i % k == 0) answer = "OK"
    println(answer)
}

Measured memory_bytes: 36408
#include<bits/stdc++.h>
using namespace std;
const long long mod = 1e9+7;
const int SZ = 1e5+5;
const int N = 3005;
long long inv[SZ*2];
long long fac[SZ*2];
long long findinv(long long a,long long b = 1e9+5)
{
    if(b==1)    return a%mod;
    long long dvd = findinv(a,b/2);
    if(b%2) return (((dvd*dvd)%mod)*a)%mod;
    return (dvd*dvd)%mod;
}
struct A
{
    long long x,y;
    bool operator<(const A&o)const
    {
        if(x!=o.x)  return x<o.x;
        return y<o.y;
    }
};
A point[N];
long long dp[N];
long long CNR(long long n,long long r)
{
    return (((fac[n]*inv[n-r])%mod)*inv[r])%mod;
}
int main()
{
    long long h,w,n;
    scanf("%lld %lld %lld",&h,&w,&n);
    fac[0] = inv[0] = 1;
    for(long long i=1;i<2*SZ;i++)  fac[i] = (i*fac[i-1])%mod,inv[i] = findinv(fac[i]);
    for(long long i=1;i<=n;i++)   scanf("%lld %lld",&point[i].x,&point[i].y);
    sort(point+1,point+n+1);
    point[++n] = {h,w};
    for(long long i=1;i<=n;i++)
    {
        long long del = 0;
        for(long long j=1;j<i;j++)
        {
            if(point[j].x<=point[i].x&&point[j].y<=point[i].y)  del+=(dp[j]*CNR(point[i].x-point[j].x+point[i].y-point[j].y,point[i].x-point[j].x))%mod,del%=mod;
        }
        dp[i] = (CNR(point[i].x+point[i].y-2,point[i].x-1)-del+mod)%mod;
    }
    printf("%lld\n",dp[n]);
    return 0;
}


Measured memory_bytes: 3964