akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

template<class F>
i64 bisect(i64 l, i64 r, F f) { // (l, r]
  if (r - l <= 1) return r;
  i64 m = l + (r - l) / 2;
  return f(m) ? bisect(l, m, f) : bisect(m, r, f);
}

template<class F>
i64 bisect_left(i64 l, i64 r, F f) {
  return bisect(l, r, [=](i64 x) { return !f(x); }) - 1;
}
int main() {
    int n;
    cin >> n;
    vector<int> b(n + 1);
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        b[a]++;
    }
    sort(begin(b), end(b));
    auto it = remove(begin(b), end(b), 0);
    b.erase(it, end(b));
    int m = b.size();
    vector<int> s(m + 1);
    for (int i = 1; i <= m; ++i) {
        s[i] = s[i - 1] + b[i - 1];
    }
    
    for (int k = 1; k <= n; ++k) {
        int ans = bisect_left(0, n + 1, [&](int x) {
            int i = lower_bound(begin(b), end(b), x) - begin(b);
            int t = s[i] + (m - i) * x;
            return t / k >= x;
        });
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int main() {
    fastio;
    ll N,M;
    cin >> N >> M;
    vector<pair<int,int>> m(M);
    rep(i,M) {
        int s;
        char c;
        cin >> s >> c;
        --s;
        m[i] = {s,c};
    }
    ll ans=-1;
    rep(i,1000) {
        auto s = to_string(i);
        if (s.size() != N) 
            continue;
        bool match = true;
        for (auto& p : m) {
            if (p.first >= s.size() || s[p.first] != p.second)
                match = false;
        }
        if (match) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,w;
    cin>>h>>w;
    string s[30][30];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)cin>>s[i][j];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=="snuke"){
                cout<<char(j+'A')<<i+1<<endl;
            }
        }
    }

}

Measured memory_bytes: 256
s = int(input())
line = [0 for i in range(1000001)]
ans = 1
line[s] += 1
while True:
  ans += 1
  if s % 2 == 0:
    s = int(s/2)
  else:
    s = 3*s + 1
  line[s] += 1
  if line[s] > 1:
    break
print(ans)

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll n, m;
vl h;
vl a, b;
/******* define variable end *******/
int solve() {
	cin >> n >> m;
	h.resize(n);
	a.resize(m);
	b.resize(m);
	REP(i, n){
		cin >> h[i];
	}
	vector<vector<ll>> G(n);
	REP(i, m){
		cin >> a[i] >> b[i];
		G[a[i]-1].push_back(b[i]-1);
		G[b[i]-1].push_back(a[i]-1);
	}
	ll ans = 0;
	REP(i, n){
		if(G[i].size() == 0){
			ans++;
		}
	}
    REP(i, n){
    	if(G[i].size() == 0){
    		continue;
    	}
    	bool flag = true;
    	REP(j, G[i].size()){
    		if(h[G[i][j]] >= h[i]){
    			flag = false;
    		}
    	}
    	if(flag){
    		ans++;
    	}
    }
    cout << ans << endl;

	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 11356
#include <bits/stdc++.h>
using namespace std;
#define LL long long

LL x, k = 1, ans = 0, c = 100;

int main () {
	cin >> x;
	while (x > c) {
		LL d = ((c + 100) / 100 * 100 - c + k - 1) / k;
		if (x - c <= d * k) {
			ans += (x - c + k - 1) / k;
			break;
		}
		ans += d;
		c += d * k;
		//cout << c << " " << ans << endl;
		k = c / 100;
	}
	cout << ans;
	return 0;
}


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

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};


int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
    }
    int ans = 0;
    rep(i,n) {
        ans = max(ans, uf.size(i));
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 4024
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int[] h, w;
        h = new int[100];
        w = new int[100];
        int cnt=0;

        while(true){
            h[cnt] = sc.nextInt();
            w[cnt] = sc.nextInt();
            if(h[cnt]==0 && w[cnt]==0)
                break;
            cnt++;
        }
        for(int k=0; k<cnt; k++){
            for(int i=0; i<h[k]; i++){
                for(int j=0; j<w[k]; j++){
                    if(i%2 == 0){
                        if(j%2==0)
                            System.out.print("#");
                        else   
                            System.out.print(".");
                    }else{
                        if(j%2==1)
                            System.out.print("#");
                        else   
                            System.out.print(".");
                    }
                }
                System.out.println("");
            }
            System.out.println("");
        }
        sc.close();
    }
}



Measured memory_bytes: 33360
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int N, X;
  cin >> N >> X;
  int ans = 1;
  int D = 0;
  for(int i = 0; i < N; i++){
    int L;
    cin >> L;
    D += L;
    if(D <= X) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <cstring>
#include <cmath>
using namespace std;


int main(int argc, char const *argv[])
{
	char a,b;
	cin>>a>>b;
	if (a==b){cout<<"="<<endl; return 0;}
	if(a>b) cout<<">"<<endl;
	else cout<<"<"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  vector<int> x(4), y(4);
  cin >> x[0] >> y[0] >> x[1] >> y[1];
  int vx, vy;
  vx = x[1] - x[0];
  vy = y[1] - y[0];
  x[2] = x[1] - vy, y[2] = y[1] + vx;
  x[3] = x[2] - vx, y[3] = y[2] - vy;
  cout << x[2] << ' ';
  cout << y[2] << ' ';
  cout << x[3] << ' ';
  cout << y[3] << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import deque, defaultdict

N = int(input())
ab = []
for i in range(N - 1):
    ab.append(tuple(map(int, input().split())))

c_list = list(map(int, input().split()))
c_list.sort()
c_que = deque(c_list)

cnt = defaultdict(int)
outs = defaultdict(list)
for a, b in ab:
    cnt[a - 1] += 1
    cnt[b - 1] += 1
    outs[a - 1].append(b - 1)
    outs[b-1].append(a-1)

cnt = sorted(cnt.items(), key=lambda x:-x[1])
top = cnt[0][0]
tar = defaultdict(lambda: 0)

import sys
sys.setrecursionlimit(10 ** 9)
visit = [False] * N

def dfs(start):
    tmp = []
    visit[start] = True
    for v2 in outs[start]:
        if visit[v2]:
            continue
        q = c_que.pop()
        tar[v2] = q
        tmp.append(v2)
    for v2 in tmp:
        if visit[v2]:
            continue
        dfs(v2)

tar[top] = c_que.pop()
dfs(top)
ans = 0
for a, b in ab:
    a -= 1
    b -= 1
    ans += min(tar[a], tar[b])
print(ans)
for i in range(N):
    print(tar[i], end=" ")




Measured memory_bytes: 15168
import java.util.Scanner;


public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long X = Long.parseLong(sc.next());
        long Y = Long.parseLong(sc.next());
        
        int count = 1;
        
        while(X*2 <= Y){
            X = X*2;
            count++;
        }
        
        System.out.println(count);
    }
    
}

Measured memory_bytes: 21844
a, b, x = map(int, input().split())

import math

if x <= a**2*b/2:
    a2 = 2*x/(a*b)
    print(math.degrees(math.atan2(b, a2)))
else:
    b2 = 2*(b-x/(a**2))
    print(math.degrees(math.atan2(b2, a)))



Measured memory_bytes: 38384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int H = scan.nextInt();
        int W = scan.nextInt();
        int A = scan.nextInt();
        int B = scan.nextInt();
        for (int i = 0; i < H; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < W; j++) {
                if (i < B) {
                    if (j < A) {
                        sb.append(0);
                    } else {
                        sb.append(1);
                    }
                } else {
                    if (j < A) {
                        sb.append(1);
                    } else {
                        sb.append(0);
                    }
                }
            }
            System.out.println(sb.toString());
        }
    }
}


Measured memory_bytes: 31028
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextInt
  val S = in.next.toSeq

  val sizes = (1 until N).map {i =>
    val (l, r) = S.splitAt(i)
    l.distinct.intersect(r.distinct).size
  }
  println(sizes.max)
}

Measured memory_bytes: 55780
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

A,B,C=get_i.sort
puts A*B*(C-C/2)-A*B*(C/2)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define int  long long int

#define INF 1000000007
int knapSack(int W, int wt[], int val[], int n) 
{ 
   int i, w; 
   int K[n+1][W+1]; 
  
   // Build table K[][] in bottom up manner 
   for (i = 0; i <= n; i++) 
   { 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
  
   return K[n][W]; 
} 

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,W;
    cin>>n>>W;
    int wt[n],val[n];
    for(int i=0;i<n;i++)
    	cin>>wt[i]>>val[i];
    cout<<knapSack( W,  wt, val, n); 
    return 0;
}

Measured memory_bytes: 79104
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def main():
    N = int(input())
    W = [input().rstrip() for _ in range(N)]
    if len(W) != len(set(W)):
        print('No')
        exit()
    for i in range(len(W)-1):
        if W[i][-1] != W[i+1][0]:
            print('No')
            exit()

    print("Yes")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x/GCD(x,y)*y;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{

string S;
cin>>S;

int N=S.size();

deque<char> deq;

int M=0;

int k;

rep(i,N) {
if(S[i]=='A' || S[i]=='T' || S[i]=='G' || S[i]=='C'){
deq.push_back(S[i]);
k=deq.size();
M=max(M,k);
} else{
deq.clear();
}
}

cout<<M<<endl;

}

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

using namespace std;

using Graph = vector<vector<long long>>;

int main(void)
{
    long long N, M, K;
    cin >> N >> M >> K;

    vector<long long> A;
    vector<long long> B;
    vector<long long> Sa(N+1);
    vector<long long> Sb(M+1);
    int a,b;
    int amax, bmax;
    int result = 0;
    for(int i = 1 ;i <= N;i++){
        cin >> a;
        A.push_back(a);
        Sa[i] = Sa[i-1] + a;
        if(Sa[i] > K) {
            amax = i - 1;
        }
    }
    long long t = 0;
    for(int i = 1 ;i <= M;i++){
        cin >> b;
        B.push_back(b);
        t += b;
        Sb[i] = Sb[i-1] + b;
        if(Sb[i] > K) {
            bmax = i - 1;
        }
    }
    
    int j = M;
    for(int i = 0; i < N +1; i++) {
        while(j > 0 && t > K){
            j--;
            t -= B[j];
        }
        if(t> K){
            break;
        }
        result = max(result,i+j);
        if(i == N) {
            break;
        }
        t += A[i];
    }
        
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 11120
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
grid = [[0] * W for i in range(H)]
count = 0
reverse = False
for i in range(H):
    if reverse:
        for j in reversed(range(W)):
            if a[count] == 0:
                count += 1
            grid[i][j] = count+1
            a[count] -= 1
        reverse = False
    else:
        for j in range(W):
            if a[count] == 0:
                count += 1
            grid[i][j] = count+1
            a[count] -= 1

        reverse = True


for i in range(H):
    print(" ".join(map(str, grid[i])))


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

int main(){
  string x,a,ans;
  long long N;
  ans="";
  cin>>N>>x>>a;
  for(int i=0;i<N;i++){
    ans+=x[i];
    ans+=a[i];
  }
  cout<<ans<<endl;
}


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

int main(){
    int n, m, temp = 0;

    cin >> n >> m;

    int a[m];

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

    if(temp <= n){
        cout << n - temp << "\n";
    }
    else{
        cout << "-1\n";
    }
    return 0;
}

Measured memory_bytes: 3664
def examA():
    a = I(); b = I(); h = I()
    ans = (a+b)*h//2
    print(ans)


import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()

Measured memory_bytes: 38256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
using namespace std;

long long choose2(long long n) {
  return n * (n-1)/2;
}

int main() {
  int N; cin >> N;
  vector<int> A(N);
  vector<int> cnt(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i]; A[i]--;
    cnt[A[i]]++;
  }
  long long sum = 0;
  for(int i = 0; i < N; i++) {
    sum += choose2(cnt[i]);
  }

  for(int i = 0; i < N; i++) {
    long long ans = sum;
    ans -= choose2(cnt[A[i]]);
    ans += choose2(cnt[A[i]]-1);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string S;
  cin >> S;
  for (int i = 0; i < (int)S.length(); i++) {
    S[i] = (S[i] - 'A' + N) % 26 + 'A';
  }
  cout << S << '\n';
  return 0;
}


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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()

template<typename U, typename T>
void chmin(U &x, T y) { x = min(x, y); }

template<typename U, typename T>
void chmax(U &x, T y) { x = max(x, y); }

typedef long long int lli;
typedef long double ld;
typedef pair<int,int> P;

const int INF = INT_MAX/3;
const double EPS = 1e-14;
const int dx[4] = {0, 1, 0, -1}; // {-1,  0,  1, -1, 1, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0}; // {-1, -1, -1,  0, 0,  1, 1, 1};

lli fact(lli n) {
  lli ans = 1;
  while (n > 0) ans *= n--;
  return ans;
}

int main() {
  cout << fixed << setprecision(10);
  string s;
  cin >> s;
  int count[26];
  REP(i, 26) count[i] = 0;
  for (char c:s) count[c-'a']++;

  int oddcount = 0;
  REP(i, 26)
    if (count[i] % 2 == 1)
      oddcount++;
  if (oddcount > 1) {
    cout << 0 << endl;
    return 0;
  }

  int sum = 0;
  REP(i, 26) count[i] /= 2, sum += count[i];
  
  lli ans = fact(sum);
  REP(i, 26) ans = ans / fact(count[i]);
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n),b(n),c(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  for(Int i=0;i<n;i++) cin>>b[i];
  for(Int i=0;i<n;i++) cin>>c[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  Int ans=0;
  vector<Int> t(n+1,0);
  for(Int i=0;i<n;i++)
    t[i]=c.end()-upper_bound(c.begin(),c.end(),b[i]);
  for(Int i=n;i>0;i--) t[i-1]+=t[i];
  for(Int i=0;i<n;i++){
    Int x=upper_bound(b.begin(),b.end(),a[i])-b.begin();
    ans+=t[x];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3456
#include<stdio.h>
#include<string.h>
#define true 1
#define false 0
typedef long long ll;

int main(void){

int i,j;
  int n;
  int a[101];
    int c = 0;
    scanf("%d",&n);
  for(i=1;i<n+1;i++){
    scanf("%d",&a[i]);
  }
   
  for(i=1;i<=n;i=i+2){
    if(a[i] % 2 == 1) c++; 
   // printf("%d,%d\n",i,a[i]);
  }


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

return 0;
}


Measured memory_bytes: 1728
#include<stdio.h>
#include<stdlib.h>
#define END 2100000000

typedef struct cell{
	int data;
	struct cell *left;
	struct cell *right;
}cell;

cell * makecell(int x){
	cell *new=malloc(sizeof(cell));
	new->data=x;
	new->left=NULL;
	new->right=NULL;
	return new;
}

int main(){
	int q,com,x;
	cell *new;
	cell *front=makecell(END);
	cell *p=front;
	
	scanf("%d",&q);
	
	for(int i=0;i<q;i++){
		
		scanf("%d",&com);
		
		if(com==0){
			scanf("%d",&x);
			new=makecell(x);
			if(front==p){/*先頭*/
				front=new;
				new->right=p;
				p->left=new;
				p=new;
			}
			else {
				p->left->right=new;
				new->left=p->left;
				new->right=p;
				p->left=new;
				p=new;
			}
			
		}
		
		if(com==1){
			scanf("%d",&x);
			if(x>0)for(int j=0;j<x;j++)p=p->right;
			else for(int j=0;j<(-x);j++)p=p->left;
		}
		
		if(com==2){
			if(front==p){/*先頭*/
				p->right->left=NULL;
				front=front->right;
				p=front;
			}
			else {
				p->left->right=p->right;
				p->right->left=p->left;
				p=p->right;
			}
		}
	}

	
	p=front;
	while(p!=NULL){
		if(p->data!=END)printf("%d\n",p->data);
		p=p->right;
	}
	
	return 0;
	
}


Measured memory_bytes: 17284
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll n;
vector<vector<P>> witness;
bool judge(ll bit)
{
    for (ll i = 0; i < n; i++)
    {
        if (!(bit & (1 << i)))
            continue;
        for (P xy : witness[i])
        {
            ll x = xy.first;
            ll y = xy.second;
            if (y == 1 && !(bit & 1 << x))
                return false;
            if (y == 0 && (bit & (1 << x)))
                return false;
        }
    }
    return true;
}
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cin >> n;
    witness.resize(n);
    for (ll i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        for (ll j = 0; j < a; j++)
        {
            ll b, c;
            cin >> b >> c;
            witness[i].emplace_back(P(b - 1, c));
        }
    }
    ll res = 0;
    for (ll bit = 0; bit < (1 << n); bit++)
    {
        if (judge(bit))
        {
            ll cnt = 0;
            for (ll i = 0; i < n; i++)
            {
                if (bit & (1 << i))
                    cnt++;
            }
            res = max(res, cnt);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

		while(true){
			String[] tmpArray = br.readLine().split(" ");

			int n = Integer.parseInt(tmpArray[0]);
			int m = Integer.parseInt(tmpArray[1]);

			if(n == 0 && m == 0){
				break;
			}

			int[] taro = new int[n];
			int[] hanako = new int[m];
			int sumT = 0;
			int sumH = 0;

			for(int i = 0; i < n; i++){
				taro[i] = Integer.parseInt(br.readLine());
				sumT += taro[i];
			}

			for(int i = 0; i < m; i++){
				hanako[i] = Integer.parseInt(br.readLine());
				sumH += hanako[i];
			}

			int minSumI = -1;
			int minSumJ = -1;
			int minSum = Integer.MAX_VALUE;

			for(int i = 0; i < n; i++){
				for(int j = 0; j < m; j++){
					if(sumT - taro[i] + hanako[j] == sumH - hanako[j] + taro[i] && sumT - taro[i] + hanako[j] < minSum){
						minSum = sumT - taro[i] + hanako[j];
						minSumI = i;
						minSumJ = j;
					}
				}
			}
			
			if(minSumI >= 0 && minSumJ >= 0){
				System.out.println(taro[minSumI] + " " + hanako[minSumJ]);
			}
			else {
				System.out.println(-1);
			}

		}
	}

}

Measured memory_bytes: 24556
def main():
    from fractions import gcd
    A, B = map(int, input().split())
    # 1 <= A, B <= 10 ** 12
    if B > A:
        A, B = B, A
    G = gcd(A, B)
    print(1+len(set(prime_factorize(G))))

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
main()


Measured memory_bytes: 5048
#include <stdio.h>

int main()
{
    int ans = 0;
    char w;

    for (int i = 0; i < 3; i++) {
        w = getchar();
        if (w == 'R')
            ans++;
        else if(ans > 0)
            break;
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 1596
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	string s ; cin >> s ;
	ll k ; cin >> k ;
	bool ok = true ;
	for(int i=0;i<s.size();i++) ok &= (s.at(i)==s.at(0)) ;
	if(ok){
		cout << (s.size()*k)/2  << endl ;
		return 0 ;
	}
	ll f=0,b=0 ;
	for(int i=0;i<s.size();i++){
		if(s.at(i)!=s.at(0)) break ;
		f++ ;
	}
	for(int i=s.size()-1;i>=0;i--){
		if(s.at(i)!=s.at(s.size()-1)) break ;
		b++ ;
	}
	ll ans = 0 ;
	for(int i=f;i<s.size()-b;i++){
		if(s.at(i)==s.at(i+1)){
			ans++ ;
			s.at(i+1) = '?' ;
		}
	}
	if(s.at(0)==s.at(s.size()-1)) ans = ans*k+f/2+b/2+(f+b)/2*(k-1) ;
	else ans = (ans+f/2+b/2)*k ;
	cout << ans << endl ;
}


Measured memory_bytes: 3596
#include <iostream>
#include <stdint.h>
#include <map>

using namespace std;

class Map : public map<int64_t, uint64_t> {
public:
  void add(int64_t key) {
    auto itr = this->find(key);
    if (itr==this->end())
      this->emplace(key,1);
    else
      this->at(key)++;
  }

  uint64_t answer() {
    uint64_t ans = 0;
    for (auto x : *this) {
      uint64_t y = x.second;
      ans += y*(y-1)/2;
    }
    return ans;
  }

  void print() {
    for (auto x: *this) {
      cerr << x.first << ':' << x.second << endl;
    }
  }
};

int main()
{
  uint64_t N;
  Map countA;

  cin >> N;

  int64_t sum = 0;
  countA.add(sum);
  for (uint64_t n=0; n<N; ++n) {
    int64_t a;
    cin >> a;
    sum += a;
    countA.add(sum);
  }

  cout << countA.answer() << endl;
  
  return 0;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i<(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define dF2(i,a,b) for(int i=(a);i>(b);--i)
#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)
using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;

int n,k;
int a[100001];

ll sum[100001],s2[100001],s3,ans;

int main(){
	scanf("%d%d",&n,&k);
	F(i,1,n) scanf("%d",a+i), sum[i]=sum[i-1]+a[i], s2[i]=s2[i-1]+max(0,a[i]);
	ans=max(ans,max(sum[n]-sum[n-k],0ll)+s2[n-k]);
	dF(i,n,k+1){
		s3+=max(0,a[i]);
		ans=max(ans,s2[i-k-1]+max(sum[i-1]-sum[i-k-1],0ll)+s3);
	}
	printf("%lld",ans);
	return 0;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int k;
    cin >> k;

    for (int i = 0; i < k; i++)cout << "ACL";
}

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

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3648
import sys
import collections

n=int(input())
be=""
ls=[]

for _ in range(n):
  w=input()
  if _==0:
    pass
  else:
    if be[-1]==w[0]:
      pass
    else:
      print("No")
      sys.exit()
  be=w
  ls.append(w)
  
dic=collections.Counter(ls)
count=0

for j in range(n):
  if dic[ls[j]]==1:
    count+=1
  
if count==n:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <iostream>
#define ll long long
#define mem(f, x) memset(f, x, sizeof(f))
#define INF 0x3f3f3f3f
using namespace std;
const int M = 15;
const int N = 10005;
ll a, b, n;
int main( ){
    while( scanf( "%lld %lld %lld", &n, &a, &b ) != EOF ){
        ll tmp = n/( a + b );
        ll tp = n%( a + b );
        printf( "%lld\n", tmp*a + min( tp, a ) );
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

public class Main {

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

		int n = Integer.parseInt(br.readLine());

		String str[] = br.readLine().split(" ");
		Map<Long, Integer> map = new TreeMap<>(Comparator.reverseOrder());

		for (int i = 0; i < n; i++) {
			long a = Long.parseLong(str[i]);

			if (map.containsKey(a))
				map.put(a, map.get(a) + 1);
			else
				map.put(a, 1);
		}

		long w = 0;
		long h = 0;

		for (Long l : map.keySet()) {
			if (map.get(l) >= 4) {
				if (w == 0) {
					w = l;
					h = l;
				} else {
					h = l;
				}
			} else if (map.get(l) >= 2) {
				if (w == 0) {
					w = l;
				} else {
					h = l;
				}
			}
			if (w != 0 && h != 0)
				break;
		}

		System.out.println(w * h);
	}
}


Measured memory_bytes: 61816
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int n, k;
    cin >> n >> k;
    V(double) e(n);
    rep(i, n) {
        double p;
        cin >> p;
        e[i] = (1+p)/2.0;
    }

    V(double) sums(n+1, 0);
    rep(i, n) {
        sums[i+1] = sums[i]+e[i];
    }

    double res = 0;
    for(int i=0; i+k<=n; i++) {
        double t = sums[i+k]-sums[i];
        if(t > res) res = t;
    }

    cout << fixed << setprecision(7);
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int arr[n+1];
  bool flag=true;
  for(int i=1;i<=n;i++)
  {
    cin>>arr[i];
    if(arr[i]%2==0)
    {
      if(!(arr[i]%3==0 || arr[i]%5==0))
      {
        flag=false;
        break;
        
        
      }
        
      
      
    }
    
    
  }
  if(flag)
    cout<<"APPROVED"<<endl;
  else
    cout<<"DENIED"<<endl;
  
  
}

Measured memory_bytes: 3628
#include <bits/stdc++.h> 
#define pb push_back
#define sp " "
#define sl "\n"
#define fi first
#define se second
#define mp make_pair
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define rev(a) reverse(a.begin(),a.end())
#define PI 3.141592

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N=1e6+5,mod=1000000007;
int n,a[N];
set<int> S;
bool vs[N];
int main() { 
	cin.tie(0); cout.tie(0); 
	ios_base::sync_with_stdio();
	cin>>n;
	for (int i=0;i<n;i++) {
		cin>>a[i];
		if (S.count(a[i])==0) {
			for (int j=a[i]+a[i];j<=1000000;j+=a[i]) vs[j]=true;
		} else {
			vs[a[i]]=true;
		}
		S.insert(a[i]);
	}
	int c=0;
	for (int i:S) {
		if (vs[i]==false) c++;
	}
	cout<<c;
	return 0;
}
// Recuerda limites 
// Recuerda casos especiales


Measured memory_bytes: 14648
n, m = gets.split.map(&:to_i)
lmax = 0
rmin = n
m.times do |i|
  l, r = gets.split.map(&:to_i)
  lmax = l > lmax ? l : lmax
  rmin = rmin > r ? r : rmin
end

ans = (rmin - lmax + 1) > 0 ? rmin - lmax + 1 : 0

puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I n, q;
  cin >> n >> q;
  vector<V> ab(n+1);
  REP(i,n-1){
    I a,b;
    cin >> a >> b;
    ab.at(a).push_back(b);
  }
  V px(n+1);
  REP(i,q){
    px.at(i) = 0;
  }
  REP(i,q){
    I p,x;
    cin >> p >> x;
    px.at(p) += x;
  }
  queue<I> qq;
  qq.push(1);
  while (qq.size()){
    I x;
    I p = qq.front();qq.pop();
    x = p;
    REP(i,ab.at(x).size()){
      px.at(ab.at(x).at(i)) += px.at(x);
      qq.push(ab.at(x).at(i));
    }
  }
  REP(i,n+1){
    if (i == 0){
    }else if (i == n){
      cout << px.at(i) << endl;
    }else{
      cout << px.at(i) << " ";
    }
  }
  return 0;
  /*
  map<I, V> ab;
  V an(n+1);
  REP(i,n+1){
    an.at(i) = 0;
  }
  REP(i,n-1){
    I a,b;
    cin >> a >> b;
    ab[a].push_back(b);
    ab[b].push_back(a);
  }
  REP(i,q){
    I p,x;
    cin >> p >> x;
    REP(j,ab[p].size()){
      an.at(ab[p].at(j)) += x;
    }
    an.at(p) += x;
  }
  REP(i,n+1){
    if (i == 0){
    }else if (i == n){
      cout << an.at(i) << endl;
    }else{
      cout << an.at(i) << " ";
    }
  }
  return 0;
  */
}



Measured memory_bytes: 14848
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
A=n1()
Q=n0()
BC=n3(Q)

d = defaultdict(int)
for a in A:
    d[a]+=1

s=sum(A)

for b,c in BC:
    if d[b]==0:
        print(s)
        continue
    a=d[b]
    s+=(c-b)*a
    d[b]=0
    d[c]+=a
    print(s)
    

Measured memory_bytes: 38632
//
// Created by Myabu on 2020/01/25.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    int A,B,C;
    
    cin>>A>>B>>C;
    
    cout<<B*A/2<<endl;


    return 0;
}

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

// Author: Ashish
vector<int> g[2005];
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  vector<int> red(a);
  vector<int> green(b);
  vector<int> blue(c);
  for(auto&itr:red) cin>>itr;
  for(auto&itr:green) cin>>itr;
  for(auto&itr:blue) cin>>itr;
  red.push_back(-1);
  green.push_back(-1);
  blue.push_back(-1);
  sort(red.begin(), red.end(),[](int l,int r){return l>r;});
  sort(green.begin(), green.end(),[](int l,int r){return l>r;});
  sort(blue.begin(), blue.end(),[](int l,int r){return l>r;});
  int p1=0,p2=0,p3=0,standby=0;
  int answer=0;
  while(true)
  {
  	if(standby==x+y) break;
  	if(x && red[p1]==max({red[p1],green[p2],blue[p3]}))
  	{
  		answer+=red[p1];
  		p1++;
  		x--;
  		continue;
  	}
  	if(y && green[p2]==max({red[p1],green[p2],blue[p3]}))
  	{
  		answer+=green[p2];
  		p2++;
  		y--;
  		continue;
  	}
  	if(blue[p3]==max({red[p1],green[p2],blue[p3]}))
  	{
  		answer+=blue[p3];
  		standby++;
  		p3++;
  		continue;
  	}
  	if(x==0)
  	{
  		if(green[p2]==max(green[p2],blue[p3]))
  		{
  			answer+=green[p2];
  			p2++;
  			y--;
  			continue;
  		}
  		else
  		{
  			answer+=blue[p3];
  			p3++;
  			standby++;
  			continue;
  		}
  	}
  	if(y==0)
  	{
  		if(red[p1]==max(red[p1],blue[p3]))
  		{
  			answer+=red[p1];
  			p1++;
  			x--;
  			continue;
  		}
  		else
  		{
  			answer+=blue[p3];
  			p3++;
  			standby++;
  			continue;
  		}
  	}
  }
  cout<<answer;
  return 0;
}

Measured memory_bytes: 3456
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;

ll A[200005];

int main(){

	int N;

	scanf("%d",&N);

	int i;

	for(i=0;i<N;i++){
		scanf(" %lld",&A[i]);
	}

	for(i=1;i<N;i++){
		A[i]+=A[i-1];
	}

	ll ans=1ll<<60;

	for(i=1;i<=N-3;i++){

		ll sum_l=A[i];
		ll sum_r=A[N-1]-A[i];

		int l,r,mid;

		l=1;
		r=i;

		while(l<r){
			mid=(l+r)/2;
			if(A[mid]>sum_l-A[mid]){
				r=mid;
			}
			else{
				l=mid+1;
			}
		}
		ll s11,s12,s21,s22;

		s11=llabs(A[l-1]-(sum_l-A[l-1]));
		s12=llabs(A[l]-(sum_l-A[l]));

		ll ma;
		ll mi;

		if(s11<s12){
			ma=max(A[l-1],sum_l-A[l-1]);
			mi=min(A[l-1],sum_l-A[l-1]);
		}
		else{
			ma=max(A[l],sum_l-A[l]);
			mi=min(A[l],sum_l-A[l]);
		}

		l=i+2;
		r=N-1;

		while(l<r){
			mid=(l+r)/2;
			if(A[mid]-A[i]>sum_r-(A[mid]-A[i])){
				r=mid;
			}
			else {
				l=mid+1;
			}
		}

		s21=llabs(A[l-1]-A[i]-(sum_r-(A[l-1]-A[i])));
		s22=llabs(A[l]-A[i]-(sum_r-(A[l]-A[i])));

		if(s21<s22){
			ma=max(ma,max(A[l-1]-A[i],sum_r-(A[l-1]-A[i])));
			mi=min(mi,min(A[l-1]-A[i],sum_r-(A[l-1]-A[i])));
		}
		else{
			ma=max(ma,max(A[l]-A[i],sum_r-(A[l]-A[i])));
			mi=min(mi,min(A[l]-A[i],sum_r-(A[l]-A[i])));
		}
		if(ans>ma-mi){ans=ma-mi;}
	}

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

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  string s;
  ll k;
  cin>>s>>k;
  ll x;
  rep(i,s.size()) {
    if(s[i] != '1') {
      x = i;
      break;
    }
  }
  char ans;
  if(k < x + 1) {
    ans = '1';
  } else {
    ans = s[x];
  }
  cout << ans << endl;

  return 0;
}


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

struct Card{
    char suit;
    int value;
};

template<class T>
void swap(T* a, T* b)
{
    T temp = *a;
    *a = *b;
    *b = temp;
}

void bubble(struct Card A[], int N) //冒泡排序
{
    for(int i = 0; i < N; i++)
    {
        for(int j = N - 1; j > i; j--)
        {
            if(A[j].value < A[j - 1].value)
                swap(&A[j], &A[j - 1]);
        }
    }
}

void selection(struct Card A[], int N) // 选择排序
{
    for(int i = 0; i < N; i++)
    {
        int minj = i;
        for(int j = i; j < N; j++)
            if(A[j].value < A[minj].value)
                minj = j;
        swap(A[i], A[minj]);
    }
}

void print(struct Card A[], int N)
{
    for(int i = 0; i < N; i++)
    {
        if(i)
            cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

bool isStable(struct Card A[], struct Card B[], int N)
{
    for(int i = 0; i < N; i++)
    {
        if(A[i].suit != B[i].suit)
            return false;
    }
    return true;
}

int main()
{
    struct Card A[MAXSIZE], B[MAXSIZE];
    int N;
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        cin >> A[i].suit >> A[i].value;
        B[i] = A[i];
    }
    bubble(A, N);
    selection(B, N);
    print(A, N);
    cout << "Stable" << endl;
    print(B, N);
    if(isStable(A, B, N))
        cout << "Stable" << endl;
    else
        cout << "Not stable" << endl;
    return 0;
}



Measured memory_bytes: 3120
a = input().split()
b = input().split()
c = input()

A = int(a[0])
V = int(a[1])
B = int(b[0])
W = int(b[1])
T = int(c)

if (B>A):
	if(W>=V):
		print("NO")
	else:
		times = (B-A) / (V-W)
		if(times <= T):
			print("YES")
		else:
			print("NO")
else:
	if(W>=V):
		print("NO")
	else:
		times = (A-B) / (V-W)
		if(abs(times) <= T):
			print("YES")
		else:
			print("NO")


Measured memory_bytes: 9216
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

MAX = 2 * 10**6 + 10
MOD = 10**9+7

fac = [1] * MAX
f_inv = [1] * MAX

def prepare(n, mod):
    for i in range(1, n+1):
        fac[i] = (fac[i-1] * i) % mod
    
    f_inv[n] = pow(fac[n], -1, MOD)
    for i in range(n-1, 0, -1):
        f_inv[i] = (f_inv[i+1] * (i+1)) % MOD

def modcmb(n, r, mod):
    if n < 0 or r < 0:
        return 0
    if r > n:
        return 0

    return fac[n] * f_inv[r] * f_inv[n-r] % mod


def main():
    K = int(readline())
    S = readline().strip()
    N = len(S)

    prepare(N + K + 5, MOD)

    inv26 = pow(26, -1, MOD)
    pow26 = pow(26, K, MOD)
    pow25 = 1
    ans = 0
    for i in range(K+1):
        ans += (modcmb(N-1+i, i, MOD) * pow25 * pow26) % MOD
        ans %= MOD

        pow25 *= 25
        pow25 %= MOD
        pow26 *= inv26
        pow26 %= MOD

    print(ans)


if __name__ == "__main__":
    main()


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

ll pow(ll m, ll n) {
    ll ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * m % MOD;
        m = m * m % MOD;
        n >>= 1;
    }
    return ret;
}

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

    cout << pow(m, n) << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
long double EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////////////////
ll max(ll a,ll b,ll c){
    return max(a,max(b,c));
}

template<int um> class UF {
public:
    vector<int> par,rank;
    vector<int>size;
    UF() {rank=vector<int>(um,0); for(int i=0;i<um;i++){par.push_back(i);size.pb(1);}}
    int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
    int operator()(int x,int y) {
        if((x=operator[](x))==(y=operator[](y))) return x;
        if(rank[x]<rank[y]){
            size[y]+=size[x];
            return par[x]=y;//rankが小さいxの親をyにする
        }
        size[x]+=size[y];
        rank[x]+=rank[x]==rank[y]; return par[y]=x;//rankがxとyで一緒ならrank++
    }
    bool same(int x,int y){return operator[](x)==operator[](y);}
    ll si(ll pos){return size[operator[](pos)];}
};
#define N 3005
//UF<N>uf;//Nはconst intじゃないとダメ
//uf(a,b);//aとbをつなぐ
//uf.same(a,b);//aとbが連結成分か判定
//uf[i];//iの親をreturn

int main(){fastio;
    /*UF<N>x;
    rep(i,0,10){
        ll a,b;cin>>a>>b;
        x(a,b);
        cout<<x.si(a)<<" "<<x.si(b)<<endl;
    }*/
    ll h,w;cin>>h>>w;
    string s[h];rep(i,0,h-1)cin>>s[i];
    ll a[h][w];memset(a,0,sizeof(a));
    rep(i,1,h-1){
        rep(j,1,w-1){
            ll c=0;
            rep(xi,i-1,i){
                rep(xj,j-1,j){
                    if(s[xi][xj]=='#')c++;
                }
            }
            if(c%2==0)a[i][j]=1;
        }
    }
    rep(j,1,w-1){
        for(ll i=h-2;i>=1;i--){
            if(a[i][j]==1)a[i][j]+=a[i+1][j];
        }
    }
    /*
    rep(i,1,h-1){
        rep(j,1,w-1){
            cout<<a[i][j]<<" ";
        }cout<<endl;
    }*/
    
    ll ans=0;
    rep(i,1,h-1){
        UF<N>uf;
        vector<l_l>v;
        rep(j,1,w-1){
            v.pb(l_l(a[i][j],j));
        }
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        for(auto x:v){
            ll pos=x.second;
            uf(pos,pos+1);
            Max(ans,(a[i][pos]+1)*uf.si(pos));
        }
    }
    cout<<max(h,w,ans)<<endl;
    
    
    return 0;
}


Measured memory_bytes: 35840
import heapq
import math
n, m = map(int,input().split())
a = list(map(int, input().split()))
item = []
ans = 0

for i in range(n):
  heapq.heappush(item, -a[i])

for i in range(m):
  tmp = heapq.heappop(item)
  heapq.heappush(item, tmp/2)

for i in range(n):
  ans += math.floor(-item[i])
  
print(ans)
  

Measured memory_bytes: 14536
import math
n = int(raw_input())

xy = [[0, 0, 0]]
for _ in xrange(n):
	xy.append([int(x) for x in raw_input().split()])

flag = True
for i  in xrange(0, n):
	t1, x1, y1 = xy[i]
	t2, x2, y2 = xy[i+1]
	xx = (t2-t1) - math.fabs(x2-x1) - math.fabs(y2-y1)
	if xx  < 0:
		flag = False
		break
	if xx % 2 != 0:
		flag = False
		break
if flag:
	print 'Yes'
else:
	print 'No'


Measured memory_bytes: 19972