akhauriyash/Code-Regression huggingface dataset:
public class Main {


  private static void solve() {
    int n = ni();
    int[][] a = ntable(n, n);

    int m = 1 << n;
    long[][] dp = new long[n + 1][m];
    dp[0][0] = 1;

    for (int i = 0; i < n; i ++) {
      for (int j = 0; j < m; j ++) {
        if (i != Integer.bitCount(j)) continue;

        for (int s = 0; s < n; s ++) {
          if (a[i][s] == 1) {
            dp[i + 1][j | (1 << s)] += dp[i][j];
            dp[i + 1][j | (1 << s)] %= 1000000000 + 7;
          }
        }
      }
    }
    
    
    System.out.println(dp[n][m - 1]);
  }
  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 383572
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;
int main(void){
  int N,i;
  int a[100100];
  int tmp,res=0;
  
  cin>>N;
  for(i=1;i<=N;i++) {
    cin>>tmp;
    a[i]=tmp;
  }

  for(i=1;i<=N;i++){
    if(i==a[a[i]]) res++;
  }
  cout<<res/2<<endl;
  return 0;
}

Measured memory_bytes: 640
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)

// cout<<fixed<<setprecision(15)
static const int COUNTER_CLOCKWISE=1;
static const int CLOCKWISE=-1;
static const int ONLINE_BACK=2;
static const int ONLINE_FRONT=-2;
static const int ON_SEGMENT=0;

//点またはベクトル
class Point{
  public:
  double x,y;
  
  Point(double x=0, double y=0): x(x),y(y) {}
  
  Point operator+(Point p){return Point(x+p.x,y+p.y);}
  Point operator-(Point &p){return Point(x-p.x,y-p.y);}
  Point operator*(double a){return Point(a*x,a*y);}
  Point operator/(double a){return Point(x/a,y/a);}
  
  bool operator<(const Point &p) const{
    return x != p.x ? x<p.x : y<p.y;
  }
  
  bool operator==(const Point &p) const{
    return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
  }
};
typedef Point Vector;
//ベクトルの二乗和と絶対値
double norm(Point p){return p.x*p.x+p.y*p.y;}
double abs(Point p){return sqrt(norm(p));}
//線分または直線
struct Segment{Point p1,p2;};
typedef Segment Line;
//円
class Circle{
public:
  Point c;
  double r;
  Circle(Point c=Point(), double r=0.0): c(c), r(r) {}
};
//多角形
typedef vector<Point> Polygon;
//内積
double dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
//外積
double cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
//直交判定
bool isOrthgonal(Vector a,Vector b){return equals(dot(a,b), 0.0);}
//平行判定
bool isParallel(Vector a,Vector b){return equals(cross(a,b), 0.0);}
//射影
Point project(Segment s,Point p){
  Vector base=s.p2-s.p1;
  double r=dot(p-s.p1,base)/norm(base);
  return s.p1+base*r;
}
//反射
Point reflect(Segment s,Point p){return p+(project(s,p)-p)*2.0;}
//点と点の距離
double getDisPP(Point a,Point b){return abs(a-b);}
//直線と点の距離
double getDisLP(Line l,Point p){return abs(cross(l.p2-l.p1,p-l.p1))/abs(l.p2-l.p1);}
//線分と点の距離
double getDisSP(Segment s,Point p){
  if(dot(s.p2-s.p1,p-s.p1)<0.0) return abs(p-s.p1);
  if(dot(s.p1-s.p2,p-s.p2)<0.0) return abs(p-s.p2);
  return getDisLP(s,p);
}
//線分と線分の距離
double getDisSS(Segment s1,Segment s2){
//  if(intersect(s1,s2)) return 0.0;
  return min(min(getDisSP(s1,s2.p1),getDisSP(s1,s2.p2)),
             min(getDisSP(s2,s1.p1),getDisSP(s2,s1.p2)));
}
//反時計周りCounter-Clockwise
int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>EPS) return COUNTER_CLOCKWISE;
  if(cross(a,b)<-EPS) return CLOCKWISE;
  if(dot(a,b)<-EPS) return ONLINE_BACK;
  if(norm(a)<norm(b)) return ONLINE_FRONT;
  return ON_SEGMENT;
}

int main(){
  Point p0,p1,p2;
  int q;
  
  cin>>p0.x>>p0.y>>p1.x>>p1.y>>q;
  
  rep(i,q){
    cin>>p2.x>>p2.y;
    int c=ccw(p0,p1,p2);
    if(c==1) cout<<"COUNTER_CLOCKWISE"<<endl;
    else if(c==-1) cout<<"CLOCKWISE"<<endl;
    else if(c==2) cout<<"ONLINE_BACK"<<endl;
    else if(c==-2) cout<<"ONLINE_FRONT"<<endl;
    else cout<<"ON_SEGMENT"<<endl;
  }
    
  return 0;
}


Measured memory_bytes: 3208
N,K=map(int,input().split())
A=list(map(int,input().split()))
low=0
high=max(A)
while high-low>1:
    mid=(low+high)//2
    cnt=0
    for i in A:
        cnt+=(i-1)//mid
    if cnt>K:
        low=mid
    else:
        high=mid
print(high)

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

int main(){
  int K,X;
  cin >> K >> X;
  for(int i=X-K+1; i<=X+K-1; i++){
    if(i!=X+K-1) cout << i << ' ' << endl;
    else cout << i << endl;
  }
}

Measured memory_bytes: 256
l_0 = list(map(int,input().split()))

l_1 = []
l_1.append(l_0[1])
l_1.append(l_0[0])
l_1.append(l_0[2])

l_2 = []
l_2.append(l_1[2])
l_2.append(l_1[1])
l_2.append(l_1[0])

print('{} {} {}'.format(l_2[0],l_2[1],l_2[2]))

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {
    int A[3];
    REP(0, i, 3) {
        cin >> A[i];
    }

    sort(A, A + 3);

    cout << A[2] - A[0] << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int S = scan.nextInt();
    int h, m, s;
    h = S / (60 * 60);
    S = S % (60 * 60);
    m = S / 60;
    S = S % 60;
    s = S;
    System.out.println(h + ":" + m + ":" + s);
  }
}

Measured memory_bytes: 26268
N = int(input())
Ts = list(map(int, input().split()))
M = int(input())
PX = [list(map(int,input().split())) for _ in range(M)]

X = [PX[i][1] for i in range(M)]
for px in PX:
    print(sum(Ts) - Ts[px[0]-1] + px[1])

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

int main(){
    int N; cin >> N;
    ll ans = 0;
    for (int i = 1; i <= N; i++)
    {
        if(i%3!=0 && i%5!=0) ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
from collections import Counter
import sys
input=sys.stdin.readline


def solve():
    N, M = map(int, input().split())
    *A, = map(int, input().split())
    *B, = map(int, input().split())
    c = Counter()
    MOD = 10**9+7
    used = set()

    for i in range(N):
        for j in range(M):
            if A[i]==B[j]:
                if A[i] in used:
                    print(0)
                    return
                else:
                    used.add(A[i])
            c[min(A[i], B[j])] += 1

    cd = 0
    ans = 1
    bef = 0
    for i, j in sorted(c.items()):
        cd += (i - bef)
        if i not in used:
            ans *= j
        cd -= 1
        for k in range(j-1):
            ans *= (cd-k)
            ans %= MOD
        cd -= j-1
        bef = i
    print(ans%MOD)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 41968
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

long long pow_mod(long long n,long long k,long long m){
    if (k == 0){
        return 1;
    } else if (k % 2 == 1){
        return pow_mod(n,k-1,m)*n % m;
    } else {
        long long t = pow_mod(n,k/2,m);
        return t*t % m;
    }
}


int main(){
    string s,t; cin >> s >> t;
    for(int i = 0; i < s.size(); i++){
        bool flg = true;
        for(int j = 0; j < t.size(); j++){
            if (s[i+j] != t[j]){
                flg = false;
                break;
            }
        }
        if (flg) cout << i << endl;
    }
}
  




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

int main() {
  int N,L;
  cin >> N>>L;
  vector<string> S(N);
  rep(i,N) {
    string s;
    cin >>s;
    S.at(i) = s;
  }

  sort(S.begin(),S.end());
  string min_S;
  for(auto x:S) {
    min_S += x;
  }
  cout << min_S << endl;
}

Measured memory_bytes: 256
class UnionFind:
    __slots__ = ["nodes", "weight"]
    
    def __init__(self, n: int) -> None:
        self.nodes = [-1]*n
        self.weight = [0]*n
        
    def get_root(self, x:int) -> int:
        if x<0:
            raise ValueError("Negative Index")
        
        if self.nodes[x]<0:
            return x
        else:
            parent, self.nodes[x] = self.nodes[x], self.get_root(self.nodes[x])
            self.weight[x] += self.weight[parent]
            return self.nodes[x]

    def unite(self, x:int, y:int) -> None:
        if x<0 or y<0:
            raise ValueError("Negative Index")
            
        root_x, root_y = self.get_root(x), self.get_root(y)
        if root_x != root_y:
            if self.nodes[root_x] < self.nodes[root_y]:
                bigroot, smallroot = root_x, root_y
            else:
                bigroot, smallroot = root_y, root_x
                
            self.nodes[bigroot] += self.nodes[smallroot]
            self.nodes[smallroot] = bigroot

    def relate(self, smaller:int, bigger:int, diff_weight:int) -> None:
        if smaller<0 or bigger<0:
            raise ValueError("Negative Index")
            
        s_root, b_root = self.get_root(smaller), self.get_root(bigger)
        if s_root == b_root:
            if self.weight[smaller] + diff_weight == self.weight[bigger]:
                return
            raise ValueError
            
        else:
            self.weight[b_root] = diff_weight - self.weight[bigger]
            self.nodes[s_root] += self.nodes[b_root]
            self.nodes[b_root] = smaller
            
   
         
N,M = map(int, input().split())
LRD = []
for _ in range(M):
    LRD.append(tuple(map(int, input().split())))
 
uf = UnionFind(N)
relate = uf.relate    

try:
    for l,r,d in LRD:
        relate(l-1,r-1,d)
    print("Yes")
except Exception as e:
    print("No")

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

ll t1, t2;
ll a1, a2;
ll b1, b2;

void solve() {
  ll s, t;
  s = a1*t1 - b1*t1;
  t = s + a2*t2 - b2*t2;
  if (t == 0) cout << "infinity" << endl;
  else if ((s>0 && t>0) || (s<0 && t<0)) cout << 0 << endl;
  else {
    ll u = (s > 0 ? s / (-t) : (-s) / t);
    ll v = (s > 0 ? s % (-t) : (-s) % t);
    cout << u*2LL + (v ? 1LL : 0LL) << endl;
  }
}

int main() {
  cin >> t1 >> t2;
  cin >> a1 >> a2;
  cin >> b1 >> b2;
  solve();
  return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	x = 0
	for i in 1:n
		l,r = readline() |> split |> parseMap
		x+=(r-l+1)
	end
	println(x)
end

main()

Measured memory_bytes: 110204
import java.util.Scanner;
public final class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] day = new int[n][3];
        int[][] dp = new int[n][3];
        for(int i=0; i<n; i++){
            for(int j=0; j<3; j++){
                day[i][j] = sc.nextInt();
            }
        }
        int max = 0;
        for(int i=0; i<3; i++){
            dp[0][i] = day[0][i]; 
            if(max < day[0][i])
                max = day[0][i];
        }
        int val = 0;
        for(int i=1; i<n; i++){
            for(int j=0; j<3; j++){
                if(j==0)
                    val = Math.max(dp[i-1][1],dp[i-1][2]);
                else if(j==1)
                    val = Math.max(dp[i-1][0],dp[i-1][2]);
                else
                    val = Math.max(dp[i-1][0],dp[i-1][1]);
                dp[i][j] = day[i][j] + val; 
                if(dp[i][j]>max)
                    max = dp[i][j];  
            }   
        }
        System.out.println(max);
        sc.close();
    }
}

Measured memory_bytes: 101704
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;


int main() {
	int n;
	cin >> n;
	vector<pair<int, int>> r;
	vector<pair<int, int>> b;
	for (int i = 0; i < n; ++i) {
		int ai, bi;
		cin >> ai >> bi;
		r.push_back(make_pair(ai, bi));
	}
	sort(r.begin(), r.end());
	for (int i = 0; i < n; ++i) {
		int ai, bi;
		cin >> ai >> bi;
		b.push_back(make_pair(ai, bi));
	}
	sort(b.begin(), b.end());
	int matched = 0;
	for (int i = 0; i < b.size(); ++i) {
		int cand = -1;
		int candy = 0;
		for (int j = 0; j < r.size(); ++j) {
			if (r[j].first < b[i].first && r[j].second < b[i].second) {
				if (cand == -1) {
					cand = j;
					candy = r[j].second;
				}
				else {
					if (candy < r[j].second) {
						cand = j;
						candy = r[j].second;
					}
				}
			}
		}
		if (cand != -1) {
			matched++;
			r.erase(r.begin() + cand);
		}
	}
	cout << matched << endl;
	return 0;
}

Measured memory_bytes: 256
def modInv(a,mod):
  return pow(a,mod-2,mod)

def nCr(n,r,mod):
  r=min(r,n-r)
  if r==0:
    return 1
  if r==1:
    return n
  numer=1
  denom=1
  for i in range(r):
    numer=(n-i)*numer%mod
    denom=(i+1)*denom%mod
  return numer*modInv(denom,mod)%mod

n,a,b=map(int,input().split())
mod=10**9+7
f=pow(2,n,mod)-1
A=nCr(n,a,mod)
B=nCr(n,b,mod)
print((f-A-B)%mod)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,w=0;
  string s;

  std::cin >> x;
  repone(i,x+1){
    if(i%3==0||i%5==0){
      continue;
    }else{
      y+=i;
    }
  }
  std::cout << y << '\n';
}


Measured memory_bytes: 3628
n,m=map(int,input().split())
fib=[0]*(n+2)
fib[0]=0
fib[1]=1
for i in range(n):
  fib[i+2]=fib[i]+fib[i+1]
ans=1
k=0
for i in range(m):
  a=int(input())
  ans*=fib[a-k]
  k=a+1
ans*=fib[n-k+1]
print(ans%1000000007)

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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin>>n;
	int cnt = 0;
	for(int i=0;i<n;i++) {
		int x,y;
		cin>>x>>y;
		if(x==y) {
			cnt++;
		}
		else {
			cnt = 0;
		}
		if(cnt ==3) {
			cout<<"Yes";
			return 0;
		}
	}	
	cout<<"No";

	return 0;
}

Measured memory_bytes: 3652
#include <iostream>

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

using namespace std;

int main(){
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  A--; B--; C--; D--;
  string S;
  cin >> S;
  //入力終了

  //(A, C)に2マス連続で岩があればNG
  for(int i=A+1; i<=C-1; i++){
    if(S[i] == '#' && S[i+1] == '#'){
      cout << "No" << endl;
      return 0;
    }
  }

  //(B, D)に2マス連続で岩があればNG
  for(int i=B+1; i<=D-1; i++){
    if(S[i] == '#' && S[i+1] == '#'){
      cout << "No" << endl;
      return 0;
    }
  }

  //2マス連続で岩がないとき
  //C < Dなら上手く移動できる
  if(C < D){
    cout << "Yes" << endl;
    return 0;
  }
  //D < Cのとき，どこかで追い越す必要がある
  else{
    for(int i=B-1; i<=D-1; i++)
      //3マス連続で空白があればOK
      if(S[i] == '.' && S[i+1] == '.' && S[i+2] == '.'){
	cout << "Yes" << endl;
	return 0;
      }
  }
    
  //上のループを抜けるならダメ
  cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  rep(i, N) cin >> P[i];
  int cnt = 0;
  rep(i, N)
    if(P[i] != i+1)
      cnt++;
  if(cnt == 2 || cnt == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# heapq
import heapq
class Reverse:
    def __init__(self, val):
        self.val = val
        
    def __lt__(self, other):
        return self.val > other.val
        
    def __repr__(self):
        return repr(self.val)
    
class Heapq:
    def __init__(self, arr, desc = False):
        if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
        self.desc = desc
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        if self.desc: return heapq.heappop(self.hq).val
        else: return heapq.heappop(self.hq)
 
    def push(self, a):
        if self.desc: heapq.heappush(self.hq, Reverse(a))
        else: heapq.heappush(self.hq, a)
 
    def top(self):
        if self.desc: return self.hq[0].val
        else: return self.hq[0]

from operator import itemgetter
def index_sort(A):
    A_sort = sorted(enumerate(A),key=itemgetter(1))
    index = [a[0] for a in A_sort]
    sorted_A = [a[1] for a in A_sort]
    return index, sorted_A

X,Y,A,B,C = LI()
p = LI()
q = LI()
r = LI()

Z = []
for i in range(A):
    Z.append((p[i],0)) # red
for i in range(B):
    Z.append((q[i],1)) # green
for i in range(C):
    Z.append((r[i],2))

Z.sort(key=lambda x:(-x[0],-x[1]))
index = [Z[i][1] for i in range(len(Z))]

R = []
G = []
M = []
Rm = Heapq([])
Gm = Heapq([])
ans = 0

for i in range(X+Y):
    ans += Z[i][0]
    if Z[i][1] == 0:
        R.append(Z[i][0])
        Rm.push(Z[i][0])
    elif Z[i][1] == 1:
        G.append(Z[i][0])
        Gm.push(Z[i][0])
    else:
        M.append(Z[i][0])
        #Rm.push(Z[i][0])
        #Gm.push(Z[i][0])

nr = len(R)
ng = len(G)
nm = len(M)
for i in range(X+Y,A+B+C):
    if ng+nm < Y:
        if Z[i][1] == 0:
            continue
        else:
            v = Rm.pop()
            #Gm.push(Z[i][0])
            ng += 1
            nr -= 1
            ans -= v
            ans += Z[i][0]
    elif nr+nm < X:
        if Z[i][1] == 1:
            continue
        else:
            v = Gm.pop()
            #Rm.push(Z[i][0])
            nr += 1
            ng -= 1
            ans -= v
            ans += Z[i][0]
    else:
        break

print(ans)

Measured memory_bytes: 120744
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x) {
	return(x + 9) / 10 * 10;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	string S;
	cin >> S;
	int N = S.size();
	vector<int> c;
	int zero = 0;
	int one = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == '0') {
			zero = zero + 1;
		}else{
			one = one + 1;
		}
	}
	cout << N -abs(one - zero);
}

Measured memory_bytes: 512
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
type I = usize;

const MOD: usize = 1e9 as usize + 7;

fn add(a: usize, b: usize) -> usize {
    (a + b%MOD) % MOD
}

fn main() {
    input!{
      n: usize,
      x: usize,
      mut ss: [usize; n],
    }
    ss.sort();
    ss.reverse();

    let mut dp = vec![vec![0; x+1]; n+1];
    dp[0][x] = 1;

    for i in 0..n {
        for j in 0..x+1 {
            dp[i+1][j%ss[i]] = add(dp[i+1][j%ss[i]], dp[i][j]);
            dp[i+1][j] = add(dp[i+1][j], dp[i][j] * (n-i-1));
        }
    }

    let mut ans = 0;
    for j in 0..x+1 {
        ans = add(ans, dp[n][j] * j);
    }
    println!("{}", ans);
}


Measured memory_bytes: 209148
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    ll A, B, N;
    cin >> A >> B >> N;

    if (B > N) {
        ll x = N;
        cout << (A * x) / B - A * (x / B) << endl;
    }
    else {
        ll x = B - 1;
        cout << (A * x) / B - A * (x / B) << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n; cin >> n;
  vector<int> x(n), r(n);
  int l = -1, rr = 1e6;
  for(int i = 0; i < n; i++){
    cin >> x[i] >> r[i];
    l = max(l, x[i] - r[i]);
    rr = min(rr, x[i] + r[i]);
  }

  auto f = [&](double t){
    double h = 1e6;
    for(int i = 0; i < n; i++){
      double dx = t - x[i];
      if(abs(dx) > r[i]) return -1.0;
      h = min(h, sqrt(r[i]*r[i] - dx*dx));
    }
    return h;
  };
  
  double left = l, right = rr;
  //[left , t1 , t2 , right]
  for(int lim = 0; lim < 80; lim++){
    double t1 = (left * 2 + right) / 3;
    double t2 = (left + right * 2) / 3;
    (f(t1) <= f(t2) ? left = t1 : right = t2);
  }
  printf("%.9f\n", f(left));

  return 0;
}


Measured memory_bytes: 4412
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      string[] input = Console.ReadLine().Split();
      int a = int.Parse(input[0]);
      int b = int.Parse(input[1]);
      int c = int.Parse(input[2]);
      
      if ((a+b)>=c)
      {
        Console.WriteLine("Yes");
      }
      else
      {
        Console.WriteLine("No");
      }
    }
}


Measured memory_bytes: 27276
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(0);
}

signed main(){
    init();
    run();
    return 0;
}

#define N 100

int nCr[N+1][N+1];

int make_nCr(){
	REP(i,1,N)nCr[i][0]=nCr[i][i]=1;
	REP(i,2,N){
		REP(j,1,i)nCr[i][j]=nCr[i-1][j-1]+nCr[i-1][j];
	}
}

void run(){
	make_nCr();
    int l,k;
    cin>>l>>k;
    int ans=0;
    for(int i=1;i<=l;i+=2){
        int n=i/2+1;
        rep(j,n+1){
            if(i+j*(k-1)>l)break;
			ans+=nCr[n][j];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3304
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

// GCD : greatest common divisor (GCD) via Euclidean algorithm
func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

// LCM : find Least Common Multiple (LCM) via GCD
func LCM(a, b int, integers ...int) int {
	result := a / GCD(a, b) * b

	for i := 0; i < len(integers); i++ {
		result = LCM(result, integers[i])
	}

	return result
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}
	gcd := a[0]
	for i := 1; i < N; i++ {
		gcd = GCD(gcd, a[i])
	}
	out(gcd)
}


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

int main()
{
    std::string S;
    std::cin >> S;
    long K;
    std::cin >> K;
    char notone ='1';
    int flag=0;
    for(long i=0; i<S.length(); i++){
        if(S[i]!='1'){
            notone=S[i];
            if(i<=K-1){
                flag=1;
            }
            break;
        }
    }
    if(flag==1){
        std::cout << notone << std::endl;
    }else{
        std::cout << 1 << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	string s;
	cin>>s;
	int q;
	cin>>q;
	while(q--){
		int k;
		cin>>k;
		ll cnt1=0,cnt2=0,cnt3=0;//D,M,DM部分列のカウント
		ll ans=0;
		rep(i,n){
			if(i<=k-1){
				if(s[i]=='D'){
					cnt1++;
				}
				if(s[i]=='M'){
					cnt2++;
					cnt3+=cnt1;
				}
				if(s[i]=='C'){
					ans+=cnt3;
				}
			}else{
				if(s[i-k]=='D'){//区間に含まれるDの数と部分列の数が減る
					cnt3-=cnt2;
					cnt1--;
				}
				if(s[i-k]=='M'){
					cnt2--;
				}
				if(s[i]=='D'){
					cnt1++;
				}
				if(s[i]=='M'){
					cnt2++;
					cnt3+=cnt1;
				}
				if(s[i]=='C'){
					ans+=cnt3;
				}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1948
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A == 7){
		if(B == 5 && C == 5){
			cout << "YES" << endl;
        }
		else cout << "NO" << endl;
    }
	else if (A == 5){
		if(B == 7 && C == 5){
			cout << "YES" << endl;
        }
		else if(B == 5 && C == 7){
			cout << "YES" << endl;
        }
		else cout << "NO" << endl;
    }
}

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


int main(){
  int n;
  cin >> n;
  int ans=0,minn=300000;
  for(int i=0; i<n; i++){
    int p; cin >> p;
    if(minn>p){
      ans+=1;
      minn=p;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main() {
  int n = 3005;
  repn(i,n){
    vector<int> vec(2);
    cin >> vec.at(0) >> vec.at(1);
    if (vec.at(0) == 0 && vec.at(1) == 0){break;}
    if (vec.at(0)>vec.at(1)){
      SORT(vec);
    }
    cout << vec.at(0) << " " << vec.at(1) << endl;
  }

 
}


Measured memory_bytes: 3108
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC128
{
	class Program
	{
		static void Main(string[] args)
		{
			var nk = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
			var N = nk[0];
			var K = nk[1];
			var V = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

			var ans = 0;
			for (var a = 0; a <= K; a++)
			{
				var qA = V.Take(a).ToList();
				for (var b = 0; b <= K - a; b++)
				{
					var qB = qA.Concat(V.Skip(Math.Max(a, N - b))).OrderBy(x => x).ToList();
					for (var c = 0; c <= Math.Min(K - (a + b), qB.Count + 1); c++)
					{
						ans = Math.Max(ans, qB.Skip(c).Sum());
					}
				}
			}
			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 15568
import math
x = int(input())
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    
    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(2, math.floor(math.sqrt(num))+1):
        if num % i == 0:
            return False
    # 素数
    return True
  
for i in range(x, 10**6):
    if isPrime(i):
        print(i)
        break


Measured memory_bytes: 62932
def solve(x):
    for i in a:
        x = i * (x // i)
    return x

def solve_min(c1, c2):
    m = (c1 + c2 + 1) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        if solve(m) < 2:
            c1 = m
        else:
            c2 = m
        return solve_min(c1, c2)

def solve_max(c1, c2):
    m = (c1 + c2 + 1) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        if solve(m) <= 2:
            c1 = m
        else:
            c2 = m
        return solve_max(c1, c2)

k = int(input())
a = list(map(int, input().split()))
maxa = max(a)
mi = solve_min(maxa - 1, pow(10, 18))
ma = solve_max(maxa - 1, pow(10, 18))
ans = [mi, ma - 1]
print(-1 if mi == ma else " ".join(map(str, ans)))

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

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main(){
	string S;
	cin >> S;
	if(S[2]==S[3]&&S[4]==S[5]) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};

fn main() {
    input! {
        d: i64,
        t: i64,
        s: i64
    };

    if d / s + min(1, d % s) <= t {
        println!("{}", "Yes");
    } else {
        println!("{}", "No");
    }
}


Measured memory_bytes: 2092
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k, s;
	cin >> n >> k >> s;
	for(int i=0; i<n; i++) {
		cout << (i<k ? s : (s>2?s-1:s+1)) << " \n"[i==n-1];
	}
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>

using namespace std;

int K, S;
int sum[2505 * 2505];

int main() {
    cin >> K >> S;
    for (int i = 0; i <= K; i++)
        for (int j = 0; j <= K; j++)
            sum[i * (K + 1) + j] = i + j;

    long long res = 0;
    int size = (K + 1) * (K + 1);
    sort(sum, sum + size);
    for (int i = 0; i <= K; i++) {
        int num = S - i;
        res += upper_bound(sum, sum + size, num) - lower_bound(sum, sum + size, num);
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 28080
#include<bits/stdc++.h>
#include<string.h>
#include <math.h>
#include<iostream>
using namespace std;
typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         ld;

#define sf                  scanf
#define pf                  printf
#define srev                reverse(s.begin(),s.end())
#define sortstr             sort(s.begin(), s.end());
#define gtl(x)              getline(cin, (x))
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define PI                  acos(-1)
#define Precision(a) cout << fixed << setprecision(a)
#define FasterIO     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define CASET int ___T,cas=1;scanf("%d",&___T);while(___T--)

template <typename T> T Sqr(T x) { T n = x * x ; return n ;}
template <typename T> T Pow(T B,T P){ if(P==0) return 1; if(P&1) return B*Pow(B,P-1);  else return Sqr(Pow(B,P/2));}
template <typename T> T Abs(T a) {if(a<0)return -a;else return a;}
template <typename T> T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template <typename T> T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
//scanf("%[^\n]%*c", str);
//sort(s,s+n,greater<int>());
int main()
{
	//freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	int s, w;
	cin >> s >> w;
	if(w>=s) cout << "unsafe" << endl;
	else cout << "safe" << endl;
	return 0;
}


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

using namespace std;
const int MOD = 1e9 + 7;

int N;
int A[22][22];
int dp[22][(1<<21)+5];

int rec(int indx, int mask){
	
	if(mask==(1<<N)-1) return 1;
	if(indx>=N) return 0;
	if(dp[indx][mask]!=-1) return dp[indx][mask];
	int ret=0;
	for(int i=0;i<N;i++){
		if(A[indx][i]==1 && !((1<<i)&mask)){
			ret+=rec(indx+1,(mask|(1<<i)));
			ret=(ret%MOD);
		}
	}
	return dp[indx][mask]=ret;
}

int main (){
	
	scanf("%d", &N);
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			scanf("%d", &A[i][j]);
		}
	}
	memset(dp,-1,sizeof(dp));
	int ans=rec(0,0);
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 180480
import sys
import itertools


def peeks(f):
    readline = f.readline
    n, m = map(int, readline().split())
    h = tuple(itertools.chain(
        [0],
        map(int, readline().split())))
    observatories = tuple(tuple(map(int, line.split())) for line in f)
    # print(n, m)
    # print(f'{h=}')
    # print(f'{observatories=}')

    L = [0] * (n + 1)
    for a, b in observatories:
        L[a] = max(L[a], h[b])
        L[b] = max(L[b], h[a])

    # print(f'{L=}')
    ans = sum(1 for elevation, other in zip(h[1:], L[1:]) if elevation > other)

    return ans


def main():
    ans = peeks(sys.stdin.buffer)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 28772
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // ここにプログラムを追記
  int a, b, d;
  double c;
  cin >> a >> b;
  c = (a + b)/2.0;
  d = (a + b)/2;
  if(c - d > 0){
	cout << d + 1 << endl;
  }else{
    cout << d << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

const int MAX = 500111;
int N, Q;
char S[MAX];
int pos[MAX][27];
int cut[21][MAX];

int main() {
    scanf("%s%d", S, &Q);
    N = strlen(S);
    memset(pos, -1, sizeof pos);

    for (int i=N; i--;) {
	int d = S[i]-'a';
	pos[i][d] = i+1;
	for (int k=d; k<26; k++) {
	    if (pos[i][k] == -1) break;
	    pos[i][k+1] = pos[pos[i][k]][k];
	}
	if (pos[i][26] != -1) {
	    for (int k=0; k<d; k++) 
		pos[i][k] = pos[pos[i][26]][k];
	}
    }

    REP (i, N+10) {
	if (pos[i][26] == -1) cut[0][i] = N + 1;
	else cut[0][i] = pos[i][26];
    }
    REP (t, 20) REP (i, N+10) cut[t+1][i] = cut[t][cut[t][i]];

    REP ($, Q) {
	int L, R;
	scanf("%d%d", &L, &R);
	L--;
	for (int t=21; t--;) {
	    if (cut[t][L] <= R) L = cut[t][L];
	}
	
	puts(L == R ? "Yes":"No");

    }

    return 0;
}



Measured memory_bytes: 94848
import java.io.*
import java.util.*

fun solve(N: Int, Z: Int, W: Int, a: IntArray){
    if (N == 1) println(Math.abs(a[0] - W))
    else println(Math.max(Math.abs(a.last() - W), Math.abs(a[N-2] - a.last())))
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val Z = sc.next().toInt()
    val W = sc.next().toInt()
    val a = IntArray(N)
    for (i in 0 until N) {
        a[i] = sc.next().toInt()
    }
    solve(N, Z, W, a)
}



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

signed main(void)
{
	int n, cnt, i;
	cin >> n;
	int a[n];
	bool plus, minus;

	rep(i, n) cin >> a[i];
	i = 0;
	cnt = 1;
	plus = minus = false;
	while (i < n - 1)
	{
		if (a[i] < a[i + 1])
		{
			if (minus)
			{
				cnt++;
				i++;
				minus = false;
				continue;
			}
			plus = true;
		}
		else if (a[i] > a[i + 1])
		{
			if (plus) 
			{
				cnt++;
				i++;
				plus = false;
				continue;
			}
			minus = true;
		}
		i++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		int sum, getCoin, getBonus;
		int getSum = 0, count = 0;
		Scanner scan = new Scanner(System.in);

		getCoin = scan.nextInt();
		getBonus = scan.nextInt();
		sum = scan.nextInt();

		for(int i = 0; getSum < sum; i++) {
			count++;
		getSum += getCoin;
		if((count) % 7 == 0) {
			getSum += getBonus;
		}
	}
		System.out.println(count);
	}
}



Measured memory_bytes: 26512
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll a,b;
    cin >> a >> b;
    ll bsize=10;
    while(b>=bsize){
      bsize*=10;
    }
    ll tnum = a*bsize+b;
    ll l=1,r=1;
    while(r*r<tnum){
      l=r;
      r*=2;
    }
    ll tmp;
    while(r-l>1){
      tmp=(l+r)/2;
      if(tmp*tmp<=tnum)l=tmp;
      if(tmp*tmp>=tnum)r=tmp;
    }
    if(l*l==tnum |r*r==tnum)cout <<"Yes"<<endl;else cout <<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int Maxn=5e3+10;
const long long Inf=1e17;
pair <long long,int> sum[Maxn]; 
long long h[Maxn],p[Maxn],n,dp[Maxn][Maxn];
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>h[i]>>p[i],sum[i]=make_pair(p[i]+h[i],i);
	sort(sum,sum+n);
	for(int i=0;i<n;i++)dp[i][0]=0;
	for(int i=0;i<=n;i++)dp[0][i]=Inf;
	dp[0][1]=p[sum[0].second];
	for(int i=1;i<n;i++){
		for(int j=1;j<=n;j++){
			dp[i][j]=dp[i-1][j];
			if(h[sum[i].second]>=dp[i-1][j-1])
				dp[i][j]=min(dp[i][j],dp[i-1][j-1]+p[sum[i].second]);
		}
	}
	for(int i=n;i>=0;i--){
		if(dp[n-1][i]<Inf){cout<<i;return 0;}
	}

}

Measured memory_bytes: 196096
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; cin >> n;
  vl num(n); vl pr(n);
  
  rep(i,n){
    ll x; cin >> x; pr[i] = x-1;
    num[x-1]++;
  }
  
  ll sum = 0;
  rep(i,n){
    sum += (num[i]-1)*num[i]/2;
  }
  
  rep(i,n){
    cout << sum - num[pr[i]] + 1 << endl;
  }
  
}

Measured memory_bytes: 6412
#include <iostream>

using namespace std;

int main(void) {
	while (1) {
		int mid, fin, re;
		char record;
		cin >> mid >> fin >> re;
		if (mid == -1 && fin == -1 && re == -1) {
			break;
		}
		else if (mid == -1 || fin == -1) {
			record = 'F';
		}
		else if (mid + fin >= 80) {
			record = 'A';
		}
		else if (mid + fin >= 65) {
			record = 'B';
		}
		else if (mid + fin >= 50) {
			record = 'C';
		}
		else if (mid + fin >= 30) {
			if (re >= 50) {
				record = 'C';
			}
			else {
				record = 'D';
			}
		}
		else {
			record = 'F';
		}

		cout << record << "\n";
	}

	return 0;
}

Measured memory_bytes: 3088
def main():
	x, y = map(int, input().split())
	for a in range(x+1):
		if y == a * 2 + 4 * (x - a):
			print('Yes')
			return
	# if (y == x * 2) or (y == x*4):
	# 	print('Yes')
	# 	return

	print('No')
	return

if __name__ == "__main__":
	main()

Measured memory_bytes: 9164