akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

plus_2 = 0
minus = 0
for a, b in zip(A, B):
    if a < b:
        plus_2 += (b-a)//2
    else:
        minus += a-b

if plus_2 >= minus:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 10448
#include<bits/stdc++.h>
using namespace std;
int main()
{

  int n,k;
  cin>>n>>k;
  vector<int>v;
  for(int i=0;i<n;i++)
  {
      int x;
      cin>>x;
      v.push_back(x);
  }
  sort(v.begin(),v.end());
  cout<<accumulate(v.begin(),v.begin()+k,0)<<endl;

}


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

int main() {
  int a,b,c,d,l,r;
  cin >> a >> b >> c >> d;
  l = a + b;
  r = c + d;
  
  if (l > r) {
    cout << "Left" << endl;
  }else if (l < r) {
    cout << "Right" << endl;
  }else if (l == r) {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
typedef long long ll;
int main()
{
    ll T,i,count,ara[10000];
    scanf("%lld",&T);
    for(i=0;i<T;i++)
    {
        scanf("%lld",&ara[i]);
    }
    count=0;
    for(i=1;i+1<T;i++)
    {
        if(ara[i-1]<ara[i]&&ara[i+1]>ara[i])
        {
            count++;
        }
        else if(ara[i-1]>ara[i]&&ara[i+1]<ara[i])
        {
            count++;
        }
    }
    printf("%lld\n",count);
    return 0;
}

Measured memory_bytes: 128
/*
  距離(２点P1(x1,y1),P2(x2,y2)の距離を求めるプログラム)
  2018/03/05
*/

#include<stdio.h>
#include<math.h>

typedef struct{
  double x;
  double y;
}POINT;

int main(void)
{
  POINT p1,p2;
  double d;

  scanf("%lf %lf %lf %lf",&p1.x,&p1.y,&p2.x,&p2.y);
  if((p2.x - p1.x) != 0 && (p2.y - p1.y) != 0)
    d = sqrt(pow((p2.x - p1.x),2) + pow((p2.y - p1.y),2));
  else
    {
      if((p2.x - p1.x) == 0)
	d = fabs(p2.y-p1.y);
      else
	d = fabs(p2.x-p1.x);
    }
  printf("%f\n",d);
  return 0;
}


Measured memory_bytes: 2048
using System;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;

class abc122_C
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();
        var sp = input.Split(' ');

        var N = int.Parse(sp[0]);
        var Q = int.Parse(sp[1]);

        var S = Console.ReadLine();

        var acFoundAIndexes = new List<int>();
        var lastA = false;
        for (var i = 0; i < S.Length; i++)
        {
            switch (S[i])
            {
                case 'A':
                    lastA = true;
                    break;
                case 'C':
                    if (lastA)
                    {
                        acFoundAIndexes.Add(i-1);
                    }
                    lastA = false;
                    break;
                default:
                    lastA = false;
                    break;
            }
        }


        for (var i = 0; i < Q; i++)
        {
            input = Console.ReadLine();
            if(acFoundAIndexes.Count() == 0) {
                Console.WriteLine(0);
                continue;
            }

            sp = input.Split(' ');
            var L = int.Parse(sp[0]);
            var R = int.Parse(sp[1]);

            var indexesLIndex = BinarySearchNearRight(acFoundAIndexes, L-1);
            var indexesRIndex = BinarySearchNearLeft(acFoundAIndexes, R-2); // reject if R pos == 'A'

            if(indexesRIndex == null || indexesLIndex == null) {
                Console.WriteLine(0);
                continue;
            }
            var result = indexesRIndex - indexesLIndex + 1;

            Console.WriteLine(result);
        }
    }

    static int? BinarySearchNearLeft<T>(List<T> list, T needle) {
        var result = list.BinarySearch(needle);
        if(result >= 0){ // found exact
            return result;
        }

        var flipped = ~result;
        if(flipped == list.Count) { // larger than last element of list
            return list.Count - 1;
        }

        // if smaller than first then null
        if(flipped == 0) {
            return null;
        }
        
        // return left
        return flipped - 1;
    }

    static int? BinarySearchNearRight<T>(List<T> list, T needle) {
        var result = list.BinarySearch(needle);
        if(result >= 0){ // found
            return result;
        }

        var flipped = ~result;
        if(flipped == list.Count) { // larger than last element of list
            return null;
        }

        // return right
        return flipped;
    } 
}

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

struct box { int x[4],y[4],f,n,b[100];};

box bo[100];

int cross(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4) {
	int v1,v2,v3,v4,x5,y5,x6,y6,x7,y7;
	x5=y3-y4; y5=x4-x3; x6=x3-x1; y6=y3-y1; x7=x3-x2; y7=y3-y2;
	v1=x5*x6+y5*y6; v2=x5*x7+y5*y7;
	x5=y1-y2; y5=x2-x1; x6=x1-x3; y6=y1-y3; x7=x1-x4; y7=y1-y4;
	v3=x5*x6+y5*y6; v4=x5*x7+y5*y7;
	if (v1*v2>0 || v3*v4>0) return 0;
	if ((v1==0 && v2==0) || (v3==0 && v4==0)) return 0;
	return 1;
}

int boxin(box b,int x,int y) {
	int i,x1,y1,x2,y2;
	for (i=0;i<4;i++) {
		x1=-(b.y[(i+1) % 4]-b.y[i]); y1=b.x[(i+1) % 4]-b.x[i];
		x2=b.x[i]-x; y2=b.y[i]-y;
		if (x1*x2+y1*y2<=0) return 0;
	}
	return 1;
}

int boxcross(box a,box b) {
	int i,j,k;
	for (i=0;i<4;i++) for (j=0;j<4;j++) {
	 k=cross(a.x[(i+1) % 4],a.y[(i+1) % 4],a.x[i],a.y[i],b.x[(j+1) % 4],b.y[(j+1) % 4],b.x[j],b.y[j]);
	 if (k==1) return 1;
     }	
	if (boxin(a,b.x[0],b.y[0])==1 || boxin(b,a.x[0],a.y[0])==1) return 1; 
	return 0; 
    } 

void ans(box a) {
	int i;
	for (i=0;i<a.n;i++) if (bo[a.b[i]].f==0) { bo[a.b[i]].f=1; ans(bo[a.b[i]]);}
 }
 
    
int main() {
	int i,j,k,h,m,n,a[100];
	while(cin >> m && m>0) {
		for (h=0;h<m;h++) {
		 	cin >> n;
		 	for (i=0;i<n;i++) {
				for (j=0;j<4;j++) cin >> bo[i].x[j] >> bo[i].y[j];
				bo[i].f=bo[i].n=0;
			}
			for (i=0;i<n-1;i++) for (j=i+1;j<n;j++) {
				k=boxcross(bo[i],bo[j]);
				if (k==1) {
					bo[i].b[bo[i].n]=j; bo[j].b[bo[j].n]=i; bo[i].n++; bo[j].n++; } 
	        }
	        a[h]=0;
	        for (i=0;i<n;i++) if (bo[i].f==0) { a[h]++; bo[i].f=1; ans(bo[i]);}
	    }
	    for (i=0;i<m;i++) cout << a[i] << endl;
  }   	
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#include <unistd.h>
#include <random>

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
      cin.tie(0);
      ios::sync_with_stdio(false);
      int N, K;
      cin >> N >> K;
      vector<int> H (N);
      for(int i = 0;i < N;i++){
          cin >> H[i];
      }

      vector<int> dp (N,INF);
      for(int i = 0;i < N;i++){
          if(i == 0)dp[i] = 0;
          for(int j = 1;j <= K;j++){
              if(i+j < N)dp[i+j] = min(dp[i+j], dp[i]+abs(H[i]-H[i+j]));
              else break;
          }
      }
      cout << dp[N-1] << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
const int INF = 1001001001;

template<typename T>
inline bool chmin(T & a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int h[100005];
int dp[100005];

int main() {
	int n;
	cin >> n;
	rep(i, n) cin >> h[i];
	rep(i, n) dp[i] = INF;
	dp[0] = 0;

	for (int i = 1;i < n;i++) {
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if (i > 1)chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1] << endl;
}

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

const int MAXN = 15;
int N;
string S[MAXN];
string rem[MAXN][MAXN];
string mem[1<<MAXN][MAXN];

bool lt(const string &a, const string &b) {
  return a.size() < b.size() ||
    a.size() == b.size() && a < b;
}

string rec(int used, int prev) {
  string &res = mem[used][prev];
  if(res.size() != 1000) return res;
  if(used == (1<<N)-1) return res = "";
  for(int i = 0; i < N; ++i) {
    if(used >> i & 1) continue;
    string tmp = rem[prev][i] + rec(used | (1<<i), i);
    if(lt(tmp, res)) res = tmp;
  }
  return res;
}

int main() {
  while(cin >> N && N) {
    for(int i = 0; i < N; ++i) cin >> S[i];
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < N; ++j) {
        if(i == j) continue;
        if(S[j].find(S[i]) != string::npos) {
          swap(S[i], S[--N]);
          --i;
          break;
        }
      }
    }
    for(int i = 0; i < N; ++i) {
      rem[N][i] = S[i];
      for(int j = 0; j < N; ++j) {
        if(i == j) continue;
        for(int k = 0; k <= S[i].size(); ++k) {
          int l = S[i].size() - k;
          if(S[i].substr(k, l) == S[j].substr(0, l)) {
            rem[i][j] = "";
            while(l < S[j].size()) rem[i][j] += S[j][l++];
            break;
          }
        }
      }
    }
    fill(mem[0], mem[1<<MAXN], string(1000, '#'));
    cout << rec(0, N).size() << endl;
  }
  return 0;
}

Measured memory_bytes: 24612
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  int A = input();
  int B = input();
  
  if(A < 10 && B < 10){
    output(A*B);
  }
  else{
    output(-1);
  }

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int map[100][100],S,T,W,H;
int move(int,int);
int main()
{
  int i,j,N,x,y,max,c;
  while(1){
    scanf("%d",&N);
    if(N==0)break;
    scanf("%d%d",&W,&H);
    for(i=0;i<H;i++){
      for(j=0;j<W;j++)map[i][j]=0;
    }
    for(i=0;i<N;i++){
      scanf("%d%d",&x,&y);
      map[y-1][x-1]=1;
    }
    scanf("%d%d",&S,&T);
    max=0;
    for(i=0;i<=H-T;i++){
      for(j=0;j<=W-S;j++){
        c=move(i,j);
        if(c>max)max=c;
      }
    }
    printf("%d\n",max);
  }
  return 0;
}

int move(int ii,int jj)
{
  int i,j,count=0;
  for(i=ii;i<T+ii;i++){
    for(j=jj;j<S+jj;j++){
      if(map[i][j]==1)count++;
    }
  }
  return count;
}

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

using namespace std;

typedef long long ll;
ll dp[2][100050];
vector<int> G[100050];
int mod = (int)1e9 + 7;

void dfs(int v , int fa){
    dp[0][v] = dp[1][v] = 1;

    for(int to : G[v]){
        if(to == fa)    continue;
        dfs(to , v);
        dp[0][v] *= (dp[1][to] + dp[0][to]) % mod ;
        dp[1][v] *= dp[0][to];

        dp[0][v] %= mod;
        dp[1][v] %= mod;
    }
    return;
}



int main()
{
    int n;
    cin >> n;
    if(n == 1){
        cout << "2";
        return 0;
    }

    for(int i = 0 ; i < n - 1; i++){
        int u , v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }

    dfs(1,0);
    cout << (dp[1][1] + dp[0][1]) % mod;


    return 0;
}


Measured memory_bytes: 12800
#include<iostream>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
int H,W,S,x[40][40];
pair<int,int> dp[40][40][40][40];
vector<tuple<int,int,int,int,int> >vec;
int getsum(int ax,int ay,int bx,int by){
	int v=0;
	for(int i=ax;i<=bx;i++){
		for(int j=ay;j<=by;j++){
			v+=x[i][j];
		}
	}
	return v;
}
void init(){
	for(int i=0;i<1600;i++){
		for(int j=0;j<1600;j++){
			dp[i/40][i%40][j/40][j%40]=make_pair(0,0);
		}
	}
}
int main(){
	while(true){
		cin>>H>>W>>S;int sum=0;
		init();if(H==0 && W==0 && S==0)break;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				cin>>x[i][j];sum+=x[i][j];
			}
		}
		sum=sum-S;vec.clear();
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				for(int k=i;k<H;k++){
					for(int l=j;l<W;l++){
						int area=(k-i+1)*(l-j+1);
						int W=getsum(i,j,k,l);
						if(W<sum)continue;
						dp[i][j][k][l]=make_pair(1,W-sum);
						vec.push_back(make_tuple(area,i,j,k,l));
					}
				}
			}
		}
		sort(vec.begin(),vec.end());
		for(int i=0;i<(int)vec.size();i++){
			int lx=get<1>(vec[i]),ly=get<2>(vec[i]);
			int rx=get<3>(vec[i]),ry=get<4>(vec[i]);
			for(int j=lx;j<rx;j++){
				pair<int,int>J1=dp[lx][ly][j][ry];
				pair<int,int>J2=dp[j+1][ly][rx][ry];
				if(dp[lx][ly][rx][ry].first<J1.first+J2.first){
					dp[lx][ly][rx][ry].first=J1.first+J2.first;
					dp[lx][ly][rx][ry].second=min(J1.second,J2.second);
				}
				else if(dp[lx][ly][rx][ry].first==J1.first+J2.first){
					if(dp[lx][ly][rx][ry].second>min(J1.second,J2.second))continue;
					dp[lx][ly][rx][ry].first=J1.first+J2.first;
					dp[lx][ly][rx][ry].second=min(J1.second,J2.second);
				}
			}
			for(int j=ly;j<ry;j++){
				pair<int,int>J1=dp[lx][ly][rx][j];
				pair<int,int>J2=dp[lx][j+1][rx][ry];
				if(dp[lx][ly][rx][ry].first<J1.first+J2.first){
					dp[lx][ly][rx][ry].first=J1.first+J2.first;
					dp[lx][ly][rx][ry].second=min(J1.second,J2.second);
				}
				else if(dp[lx][ly][rx][ry].first==J1.first+J2.first){
					if(dp[lx][ly][rx][ry].second>min(J1.second,J2.second))continue;
					dp[lx][ly][rx][ry].first=J1.first+J2.first;
					dp[lx][ly][rx][ry].second=min(J1.second,J2.second);
				}
			}
		}
		cout<<dp[0][0][H-1][W-1].first<<' '<<dp[0][0][H-1][W-1].second<<endl;
	}
	return 0;
}

Measured memory_bytes: 33308
#include <cstdio>
int check(int x)
{
    int t = 0;
    for (int i = 1; i <= x; ++i)
        if (x % i == 0)
            ++t;
    return t == 8;
}
int main()
{
    int n;
    scanf("%d", &n);
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        if (i % 2 == 1)
            ans += check(i);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>

int main ()
{
    int a[3],b,c,temp,i,j;
    for(i=0;i<3;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<3;i++)
    {
        for(j=i+1;j<3;j++)
        {
            if(a[i]<a[j])
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }

    b=abs(a[1]-a[0]);
    c=abs(a[2]-a[1]);

    printf("%d\n",b+c);

    return 0;


}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int Alice = 0, Bob = 0;
  for (int k = 0; k < a.size(); k++) {
    if (k % 2 == 0) {
      Alice += a.at(k);
    }
    else {
      Bob += a.at(k);
    }
  }
  cout << Alice - Bob << endl;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define F first
#define S second
#define sz(x) (int)x.size()
#define db(x) cerr << #x << ": " << x << "\n";

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

    int N; ll K;
    cin >> N >> K;
    vi A(N);
    for(int & x : A) cin >> x;
    int p = 1, I = 1, off = 0;
    vector<int> vis(N, -1);
    for(int i=0; i<N; i++) {
        if(vis[p-1] != -1) {
            off = vis[p-1];
            I = p;
            break;
        } else {
            vis[p-1] = i;
            p = A[p-1];
        }
        if(i+1 == K) {
            cout << p << '\n';
            return 0;
        }
    }
    vi P;
    P.emplace_back(I);
    while(A[I-1] != P[0]) {
        I = A[I-1];
        P.emplace_back(I);
    }

    //for(int & x : P ) cout << x << ' '; cout << endl;
    cout << P[(K-off)%sz(P)] << endl;
}


Measured memory_bytes: 5364
require 'matrix'
loop do
  s = gets.chomp.chop
  break if s == ''

  #lookahead(?!  )
  s.gsub!(/([A-Z\)])(?![a-z\d])/, '\11')
  s.gsub!(/([A-Z][a-z])(?!\d)/, '\11')
  s.gsub!(/\((.+?)\)(\d*)/){
    as, n = $1, $2
    as.gsub(/([a-zA-Z])(\d+)/){"#{$1}#{$2.to_i * n.to_i}"}
  }
  atoms = s.scan(/[A-Z][a-z]?/)
  atoms.uniq!
  molecules = s.split('->').map{|ms| ms.split('+')}
  l = molecules[0].size
  molecules.flatten!
  m = molecules.size - 1
  n = atoms.size

  a = Matrix.build(n, m){|y, x|
    atom = atoms[y]
    k = 0
    molecules[x].scan(/#{atom}(\d+)/).each{|a|
      k += a[0].to_i
    }
    (x >= l ? -k : k).to_r
  }.to_a

  b = [0] * n
  atoms.each do |atom|
    molecules[-1].scan(/(#{atom})(\d+)/).each{|a, k|
      b[atoms.index(a)] = k.to_r
    }
  end

  # Gauss-Jordan elimination
  (0...[n,m].min).each do |i|
    pv = (i...n).max{|k| a[k][i].abs}
    a[i], a[pv] = a[pv], a[i]
    b[i], b[pv] = b[pv], b[i]
    (0...n).each do |j|
      next if i == j
      r = a[j][i] / a[i][i]
      (i...m).each do |k|
        a[j][k] -= r * a[i][k]
      end
      b[j] -= r * b[i]
    end
  end

  ans = (Matrix[*a[0,m]].inv * Vector[*b[0,m]]).to_a + [1.to_r]
  lcm = ans.map(&:denominator).reduce(&:lcm)
  puts ans.map{|x| (x * lcm).to_i} * ' '
end

Measured memory_bytes: 10148
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, a[3001];
int main(){
    cin>>n;	for(ll i = 1; i <= n; i++)	cin>>a[i];
    ll dp[2][n+1];	memset(dp, 0, sizeof(dp));
    for(ll l = n; l > 0; l--){
        for(ll r = 1; r <= n; r++){
            if(l > r)   continue;
            bool taro = ((r-l+1)&1) == (n&1);
            ll op1 = a[l] * (taro?1:-1) + dp[(l+1)%2][r];
            ll op2 = a[r] * (taro?1:-1) + dp[l%2][r-1];
            dp[l%2][r] = taro ? max(op1, op2) : min(op1, op2);
        }
    }
    cout<<dp[1][n];
}

// Time: O(N*N)

Measured memory_bytes: 3664
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>

using namespace std;

int N,M,R;
int graph[201][201];
int r[9];
int A,B,C;
int ans = 1e9;
bool used[9];

int main()
{
    //入力
    cin >> N >> M >> R;
    //グラフの初期化
    for(int i=0;i<N;i++) for(int j=0;j<N;j++) if(i != j) graph[i][j] = 1e9;
    for(int i=0;i<R;i++){
        cin >> r[i];
        r[i]--;
    }
    //グラフを作る
    for(int i=0;i<M;i++)
    {
        cin >> A >> B >> C;
        A--;
        B--;
        if(graph[A][B] > C) graph[A][B] = graph[B][A] = C;
    }
    //ワーシャルフロイド法
    for(int k=0; k<N;k++)
        for(int i=0;i<N;i++)
            for(int j=0;j<N;j++)
                graph[i][j] = min(graph[i][j],graph[i][k]+graph[k][j]);

    //訪れた場所のパターンを全列挙
    sort(r,r+R);
    do{
        int here = 0;
        for(int i = 1; i < R; i++)
        {
            here += graph[r[i-1]][r[i]];
        }
        ans = min(ans,here);
    }while (next_permutation(r,r+R));

    //出力
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
# Binary search tree I 二分探索木：挿入


class Node():

    def __init__(self, k):
        self.k = k
        self.p = None
        self.l = None
        self.r = None
    
    def __repr__(self):
        return str(self.k)


def insert(z):
    if z == T[0]:
        return
    y = None
    x = T[0]
    while x != None:
        y = x 
        if z.k < y.k:
            x = y.l
        else:
            x = y.r
    z.p = y

    if z.k < y.k:
        y.l = z
    else:
        y.r = z


def find(k):
    x = T[0]
    while True:
        if x == None:
            return False
        elif x.k == k:
            return True
        elif x.k > k:
            x = ｘ.l
        elif x.k < k:
            x = x.r


def preparse(u):
    print(" ", u.k, sep="", end="")
    if u.l != None:
        preparse(u.l)
    if u.r != None:
        preparse(u.r)


def inparse(u):
    if u.l != None:
        inparse(u.l)
    print(" ", u.k, sep="", end="")
    if u.r != None:
        inparse(u.r)


m = int(input())
T = [None for i in range(m)]
for id in range(m):
    cmd = input().split()
    if cmd[0] == "insert":
        T[id] = Node(int(cmd[1]))
        insert(T[id])
    elif cmd[0] == "print":
        inparse(T[0])
        print()
        preparse(T[0])
        print()
    elif cmd[0] == "find":
        if find(int(cmd[1])):
            print("yes")
        else:
            print("no")



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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int a, b, c;
    cin >> a >> b >> c;
  string ans = "NO";
    if(b-a== c-b){
ans="YES";
}
cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define F           first
#define S           second
#define vl          vector<ll>
#define ld          long double
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pi          3.14159265358979323

const int N = 2e5+5;
ll can[N];
ll a[N];

void solve()
{
       ll n; cin>>n;
       rep(i,1,n+1) cin>>a[i];
       ll ans=0;
       multiset<ll>m;
       rep(i,1,n+1)
       {
              multiset<ll>::iterator it = m.lower_bound(a[i]);
              if(it==m.begin()) m.insert(a[i]);
              else
              {
                     it--;
                     m.erase(it);
                     m.insert(a[i]);
              }
       }
       ans=m.size();
       cout<<ans<<endl;
}

int main(){
	int T = 1;
       //pre();
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


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

int h, w;
vector<string> a;
long long mod = 1e9+7, dp[1010][1010];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> h >> w;
	a.resize(h);
	for(int i=0; i<h; ++i) cin >> a[i];
	dp[0][0] = 1;
	for(int i=1; i<w; ++i)
		if(a[0][i] == '.')
			dp[0][i] = dp[0][i-1];
	for(int i=1; i<h; ++i)
		if(a[i][0] == '.')
			dp[i][0] = dp[i-1][0];
	for(int i=1; i<h; ++i)
		for(int j=1; j<w; ++j)
			if(a[i][j] == '.')
				dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
	cout << dp[h-1][w-1] << "\n";
}

Measured memory_bytes: 9216
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
As = list(mapint())

dv = []
for _ in range(K.bit_length() + 1):
    l = [0] * N
    dv.append(l)

dv[0] = list(map(lambda x: x-1, As))

for k in range(1, K.bit_length() + 1):
    for n in range(N):
        dv[k][n] = dv[k - 1][dv[k - 1][n]]

a = []
for i in range(K.bit_length() + 1):
    if (K>>i)&1:
        a.append(i)

now = 0
for i in a:
    now = dv[i][now]
print(now+1)

Measured memory_bytes: 196092
import java.util.Scanner;
import java.util.Arrays;

public class Main{
    public static void main(String args[]){
	Scanner in = new Scanner(System.in);
	int num = in.nextInt();
	int[] a = new int[num];
	long sum=0;
	
	for(int i=0;i<num;i++){
	    a[i] = in.nextInt();
	}

	Arrays.sort(a);

	int max = a[a.length-1];
	int min = a[0];

	for(int i=0;i<a.length;i++){
	    sum += a[i];
	}

	System.out.println(min + " " + max + " " +sum);
    }
}




Measured memory_bytes: 42288
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <random>
#include <string.h>      //文字列の代入に使う
#include <bits/stdc++.h> //piの利用で必要(M_PI)
#include <algorithm>
#include <climits>
#define rep(i, c) for (int i = 0; i < (int)c; i++) //atcoderの解説コードに利用されていたので，ある程度一般生があるかと思われる．

int main()
{
    int N, K;
    std::cin >> N >> K;

    std::vector<int> H(N);
    for (int i = 0; i < N; i++)
    {
        std::cin >> H.at(i);
    }

    std::sort(H.begin(), H.end(), std::greater<int>());
    long sum = 0;
    for (int i = K; i < N; i++)
    {
        sum += H.at(i);
    }
    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 1024
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):
	dp[i]=dp[i-1]+abs(h[i]-h[i-1])
	for j in range(2,min(k,i)+1):
		dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])

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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 2e1 + 5;

int n, m;
char A[N][N];
int D[N][N];
int DX[] = {+1, -1, 0, 0};
int DY[] = {0, 0, +1, -1};

bool IsVal(int i, int j) { return 1 <= i && i <= n && 1 <= j && j <= m && A[i][j] == '.'; }

pii BFS(pii s) {
	memset(D, 63, sizeof D);
	D[s.first][s.second] = 0;
	queue<pii> q; q.push(s);
	while (!q.empty()) {
		pii v = q.front(); q.pop();
		int x = v.first, y = v.second;
		for (int i = 0; i < 4; i++) {
			int xx = x + DX[i], yy = y + DY[i];
			if (!IsVal(xx, yy)) continue;
			if (D[x][y] + 1 < D[xx][yy]) {
				D[xx][yy] = D[x][y] + 1;
				q.push(make_pair(xx, yy));
			}
		}
	}
	pii mx = s;
	for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (A[i][j] == '.' && D[mx.first][mx.second] < D[i][j]) mx = make_pair(i, j);
	return mx;
}

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	cin >> n >> m;
	for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> A[i][j];
	int d = 0;
	pii s, e;
	for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (A[i][j] == '.') {
		pii mx = BFS(make_pair(i, j));
		if (D[mx.first][mx.second] > d) s = make_pair(i, j), e = mx, d = D[mx.first][mx.second];
	}
	cout << d << endl;

	return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const ll MOD = (1e9+7);

int main2() {
  int N = nextInt();
  int M = nextInt();

  ll X = 0;
  ll Y = 0;
  REP(i, N) {
    ll x = nextInt();
    X += (i*x) % MOD - (ll)(N-1-i) * x % MOD;
    X = (X % MOD + MOD) % MOD;
  }
  REP(i, M) {
    ll y = nextInt();
    Y += (i*y) % MOD - (ll)(M-1-i) * y % MOD;
    Y = (Y % MOD + MOD) % MOD;
  }
  ll ans = X * Y % MOD;
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;

int main()
{
    int n,k;
    cin >> n >> k;
    vector<pair<int,int>> ans;
    rep(i,n-1){
        ans.pb(make_pair(i+1,n));
    }
    int cur_pair = ((n-1)*(n-2))/2;
    bool break_flag = false;
    if(cur_pair<k){
        cout << -1;
    }else{
        reps(i,1,n){
            reps(j,i+1,n){
                if(cur_pair==k){
                    break_flag = true;
                    break;
                }
                ans.pb(make_pair(i,j));
                cur_pair--;
            }
            if(break_flag==true){
                break;
            }
        }
        cout << ans.size() << endl;
        rep(i, ans.size()){
            cout << ans[i].first << " " << ans[i].second << endl;
        }
    }
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    int count = 0;
    for(int i = 100; i >= 1; i--) {
        if(A % i == 0 && B % i == 0) {
            count++;
            if(count == K) {
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n;int sum=0;
    cin>>n;int mmax=0;
    while(n--)
    {
        int x;
        cin>>x;
        sum+=x;
        mmax=max(mmax,x);
    }
    cout<<(sum-mmax/2.0)<<endl;

    return 0;
}


Measured memory_bytes: 256
import scala.collection.mutable

object Main {

  case class Edge(v: Int, w: Long)

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val INF = Long.MaxValue
    val V = sc.nextInt()
    val G = Array.fill(V + 1)(List[Edge]())
    (0 until V - 1) foreach { _ =>
      val u, v, w = sc.nextInt()
      G(u) ::= Edge(v, w)
      G(v) ::= Edge(u, w)
    }
    val Q, K = sc.nextInt()
    val X, Y = new Array[Int](Q)
    (0 until Q) foreach { i =>
      val x, y = sc.nextInt()
      X(i) = x
      Y(i) = y
    }

    // j番目の質問クエリ、頂点xjから頂点Kを経由しつつ、頂点yjまで
    // 移動する場合の最短経路の距離を求めてください
    // ...つまり, xjからKへの最短距離, Kからyjへの最短距離の和を答えればそれが最短経路となる
    // 木に対する全点対最短路問題を事前に解いておき, クエリへ回答する
    // 木かつ ci >= 1 なので, ダイクストラ法によって全点対最短路を求めることができる.

    def dijkstra(s: Int, V: Int, E: Int, G: Array[List[Edge]]): Array[Long] = {
      val d = Array.fill[Long](V+1)(INF)
      val queue = mutable.PriorityQueue[(Long, Int)]()(Ordering.by(_._1))
      d(s) = 0L
      queue.enqueue((0L, s))

      def loop(): Unit =
        if (queue.nonEmpty) {
          val (ud, u) = queue.dequeue()
          if (d(u) < ud) loop()
          else {
            d(u) = ud
            G(u) foreach { edge =>
              if (d(edge.v) > d(u) + edge.w) {
                d(edge.v) = d(u) + edge.w
                queue.enqueue((d(edge.v), edge.v))
              }
            }
            loop()
          }
        }
      loop()
      d
    }
//
//    val d: Array[Array[Long]] =
//      Array.tabulate(V)(s => dijkstra(s + 1, V, V - 1, G))
//
//    val r = (0 until Q).map { i =>
//      d(X(i)-1)(K) + d(K-1)(Y(i))
//    }. mkString("\n")
//
//    println(r)

    // ↑普通にTLE食らう
    // ここで, ダイクストラはO(V^3)で, 普通に V <= 10^5 は通らない..
    // O(V)かO(VlogV)ぐらいにしたい
    // 常に頂点Kを経由する. しかも無向グラフなので,
    // xjからKへの最短路 <=> Kからxjへの最短路であり
    // Kからの単一始点最短経路を求めるだけでいい...

    val d = dijkstra(K, V, V - 1, G)
    val r = (0 until Q).map { i =>
      d(X(i)) + d(Y(i))
    }. mkString("\n")

    println(r)
  }

}


Measured memory_bytes: 127012
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
// #define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

    int n;
    cin>>n;
    vi in(n);
    rep(i,n)cin>>in[i];
    int c=0;
    rep(i,n){
        bool h=true;
        rep(j,i)if(in[j]>in[i])h=false;
        if(h)c++;
    }

    cout<<c<<endl;
}


Measured memory_bytes: 256
N , K = map( int , input().strip().split(" ") ) ;

arr = [ 1 for x in range ( N ) ] ;
for x in range ( K ) :
	r = input() ;
	for x in map( int, input().strip().split(" ") ) :
		arr[x-1] = 0 ;
print ( sum( arr ) ) ;

Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define debug(a) cout << #a ": " << a << endl
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
int cnt[10];
int main(void){    
    IOS;
    for (int i = 1; i <= 5; ++i){
    	int x; cin >> x;
    	cnt[x]++;
    }
    for (int i = 1; i <= 5; ++i){
    	if (!cnt[i]){
    		cout << i << endl; return 0;
    	}
    }
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  int cnt=1;
  int ans=0;
  int a[n];
  for(int i=0; i<n; i++){
    int x;
    cin >> x;
    a[i]=x;
  }
  for(int i=0; i<n; i++){
    if(a[i]!=cnt) ans++;
    else cnt++;
  }
  bool judge=false;
  for(int i=0; i<n; i++){
    if(a[i]==1) judge=true;
  }
  if(!judge) ans=-1;
  cout << ans << endl;
}


Measured memory_bytes: 1152
r1, c1, r2, c2 = map(int, input().split())
MOD = 10 **9 + 7

ans = 0

class Factorial:
    def __init__(self, n, mod):
        self.f = [1]
        self.mod = mod
        for j in range(1, n + 1):
            self.f.append(self.f[-1] * j % mod)
        self.i = [pow(self.f[-1], mod - 2, mod)]
        for j in range(n, 0, -1):
            self.i.append(self.i[-1] * j % mod)
        self.i.reverse()
    def factorial(self, j):
        return self.f[j]
    def ifactorial(self, j):
        return self.i[j]
    def comb(self, n, k):
        return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0

F = Factorial(r2 + c2 + 3, MOD)

ans = F.comb(c1 + r1, c1) - F.comb(c1 + r2 + 1, c1) - F.comb(c2 + r1 + 1, c2 + 1) + F.comb(c2 + r2 + 2, c2 + 1)

print (ans % MOD)

Measured memory_bytes: 161452
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define mod       1000000007
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define ps(s)     for(auto i:s){cout<<i<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"This is test"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll n;cin>>n;
	ll arr[n];
	multiset<int>s;
	for(int i=0;i<n;i++){cin>>arr[i];s.insert(arr[i]);}
	for(int i=0;i<n;i++){
		auto j=s.find(arr[i]);
		s.erase(j);
		cout<<*prev(s.end())<<endl;
		s.insert(arr[i]);
	}
}
int32_t main(){
	kehsihba();
	//init();
	ll t=1;
	//cin>>t;
	for(int k=1;k<=t;k++){
		//cout<<"Case "<<k<<": ";
		solve();
		//e;
	}
}

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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    b /= a;
    cout << min(b, c) << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}



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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N =int.Parse(Console.ReadLine());
            var b = Console.ReadLine().Split().Select(int.Parse).ToList();
            var ans = new List<int>();

            while (b.Count > 0)
            {
                var delete = false;
                for (var i = b.Count - 1; i >= 0; i--)
                {
                    if (b[i] == i + 1)
                    {
                        ans.Add(b[i]);
                        b.RemoveAt(i);
                        delete = true;
                        break;
                    }
                }

                if (!delete)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }

            ans.Reverse();

            Console.WriteLine(string.Join("\r\n", ans));
        }
    }
}


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

int main() {
	char S;
	cin >> S;
	if (isupper(S)) {

		cout << "A" << endl;
	}else{
		cout << "a" << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const int N = 5e5+10;

string s;
int n;

int main(){
fast;
cin>>s;
n = s.size();

for(int i=0;i<=n;i++) {
    if(s[i]=='?') {
        s[i]='D';
    }
}

cout<<s<<endl;
return 0;
}

Measured memory_bytes: 3744
#include "stdio.h"
int main(int argc, char const *argv[])
{
    int n;
    scanf("%d",&n);
    if(n==3){
        printf("YES\n");
    }else if(n==5){
        printf("YES\n");
    }else if(n==7){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 128
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0

for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if(x == 500 * i + 100 * j + 50 * k):
                ans += 1

print(ans)


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

int main() {
    long h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    
    int start = h1 * 60 + m1;
    int end = h2 * 60 + m2;
    
    
    cout << end - start - k << endl;
}


Measured memory_bytes: 3632
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)
for ai in a:
  d[ai] += 1
  
ans = 0
for key in d:
  if d[key] >= key:
    ans += (d[key] - key)
  else:
    ans += d[key]
print(ans)

Measured memory_bytes: 18672
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<List<Integer>> list = new ArrayList<>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < q; i++) {
			switch (sc.nextInt()) {
				case 0:
					list.get(sc.nextInt()).add(sc.nextInt());
					break;
				case 2:
					list.set(sc.nextInt(), new ArrayList<>());
					break;
				case 1:
					List<Integer> tmp = list.get(sc.nextInt());
					for (int j = 0; j < tmp.size(); j++) {
						System.out.print(tmp.get(j));
						if (j < tmp.size() - 1) {
							System.out.print(" ");
						}
					}
					System.out.println();
					break;
			}
		}
	}
}


Measured memory_bytes: 309316
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int l;cin>>l;
  double res=l*l*l/27.0;
  printf("%.18lf\n",res);
  return 0;
}


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

int kumi(int a, int b, int c){
	if(a==b && b==c) return 1;
	if(a==b || b==c || c==a) return 3;
	return 6;
}

int main(){
	int k, s;
	int count=0;
	int a, b, c;
	cin >> k >> s;
	for(int c=0; c<=s/3; c++){
		for(int a=c; a<=s; a++){
			b = s - a - c;
			if(k>=a && a>=b && b>=c){
				count += kumi(a,b,c);
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())

b = list(map(int, input().split()))
cnt = 0
for i in range(n):
  a = list(map(int, input().split()))
  res = c
  for j in range(m):
    res += a[j] * b[j]
  cnt += res > 0
print(cnt)

Measured memory_bytes: 3060
n = int(input())
A = list(map(int,input().split()))

Adict = {}
for i in range(1,n+1):
    Adict[A[i-1]] = i

Alist = sorted(Adict.items())
ans = [Alist[i][1] for i in range(len(Alist))]
print(*ans)

Measured memory_bytes: 71976
import bisect
N = int(input())
A = [int(input()) for _ in range(N)]

S = [0] * N

end = N
for i in range(N):
    j = bisect.bisect_left(S, A[i], end, N)
    if j <= end:
        S[j-1] = A[i]
        end -= 1
    else:
        S[j-1] = A[i]

print(N-end)


Measured memory_bytes: 7840
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  vector<vector<int>> v(m+1);
  rep(i,n){
    int a,b;
    cin >> a >> b;
    if(a<=m){
      v[m-a].emplace_back(b);
    }
  }
  ll ans = 0;
  priority_queue<int> q;
  for(int i = m; i >= 0; --i){
    rep(j,v[i].size()) q.emplace(v[i][j]);
    if(q.empty())continue;
    ans += q.top(); q.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
int main(){
    int long long  n,a[1000010],wa=0;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
        wa=wa+(a[i]-1);
    }
    cout<<wa<<'\n';
    return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n,sum=0;
  cin>>n;
  for(long long i=1;i*i<=n;i++){
    if(n%i==0 && n/i-1>i) sum+=n/i-1;}
  
  cout<<sum;
  return 0;
}

Measured memory_bytes: 256
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>


using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double;
const string FILENAME = "input";




void solve() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	int l = c * 60 + d - a * 60 - b - e;
	cout << l << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//read(FILENAME);
	int t;
	//cin >> t;
	t = 1;
	while (t--) {
		solve();
	}
	return 0; 	
}

Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {
	static String S;
	public static void main(String[]args) {
		Scanner sc=new Scanner(System.in);
		S=sc.next();
		if(S.equals("ABC")) {
			System.out.println("ARC");
		}
		else {
			System.out.println("ABC");
		}
	}
}


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

int main() {
	int n;
    cin >> n;
    double a[n],b[n];
    double sum = 0;
    for(int i=0;i<n; i++){
       cin >> a[i];
       b[i]=1/a[i];
       sum +=b[i];
    }
    cout << 1/sum <<endl; 

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(){
	int A, B;
	char S[25];
	char T[25];
	char U[25];
	
	scanf("%s %s", S, T);
	scanf("%d %d", &A, &B);
	scanf("%s", U);
	
	if(strcmp(U,S)==0){
		printf("%d %d", A-1, B);
	}else if(strcmp(U,T)==0){
		printf("%d %d", A, B-1);
	}
	return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include<iomanip>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

long long sqrt(long long N){
    for(long long i = 0; i < N; i++){
        if(i * i > N){
            return i - 1;
        }
    }
    return -1;
}
int main(){
    long long N;
    cin >> N;

    long long sqrt_N = sqrt(N);
    long long ans = 0;
    for(long long i = sqrt_N + 1; i >= 1; i--){
        if(N % i == 0 && N / i > 1){
            long long m = N / i - 1;
            if(N / m  == N % m){
                ans += m;
            } 
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256