akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		
		Tree tree = new Tree();
		for(int i = 0; i < n; i++){
			String[] tmpArray = br.readLine().split(" ");
			if(tmpArray[0].equals("insert")){
				Node node = new Node(Integer.parseInt(tmpArray[1]), null, null);
				tree.insert(node);
			}
			else {
				inorder(tree.root);
				System.out.println();
				preorder(tree.root);
				System.out.println();
			}
		}
	}

	static void preorder(Node node){
		System.out.print(" "+node.key);
		if(node.left != null){
			preorder(node.left);
		}
		if(node.right != null){
			preorder(node.right);
		}
	}
	
	static void inorder(Node node){
		if(node.left != null){
			inorder(node.left);
		}
		System.out.print(" "+node.key);
		if(node.right != null){
			inorder(node.right);
		}
	}
	
}

class Tree {
	Node root = null;
	
	public Tree(){
		
	}
	public Tree(Node root){
		this.root = root;
	}
	
	public void insert (Node node){
		Node y = null;
		Node x = this.root;
		while(x != null){
			y = x;
			if( node.key < x.key){
				x = x.left;
			}
			else{
				x = x.right;
			}
		}
		node.parent = y;
		
		if (y == null){
			this.root = node;
		}
		else if(node.key < y.key){
			y.left = node;
		}
		else {
			y.right = node;
		}
	}
}

class Node {
	int key;
	Node left = null;
	Node right = null;
	Node parent = null;
	
	public Node(int key, Node left, Node right){
		this.key = key;
		this.left = left;
		this.right = right;
	}
}

Measured memory_bytes: 151308
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define N 1000
int top;
int S[N];

void push(int);

int pop();

int main(){
  int x,y;
  top = 0;
  char s[100];

  while(scanf("%s",s) != EOF){
    if(s[0] == '+'){
      x = pop();
      y = pop();
      push(x + y);
    }
    else if(s[0] == '-'){
      y = pop();
      x = pop();
      push(x - y);
    }
    else if(s[0] == '*'){
      x = pop();
      y = pop();
      push(x * y);
    }
    else{
      push(atoi(s));
    }
  }

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

  return 0;
}

void push(x){
  S[++top] = x;
}

int pop(){
  top--;
  return S[top + 1];
}



Measured memory_bytes: 2108
#include<stdio.h>
int P(int x)
{
	if(x==2)return 1;
	if(x%2==0)return 0;
	for(int i=3;i*i<=x;i+=2)if(x%i==0)return 0;
	return 1;
}
int main()
{
	int r,n,i;
	while(scanf("%d",&n),n)
	{
		if(P(n))puts("0");
		else
		{
			r=2;
			for(i=1;!P(n+i);++i)++r;
			for(i=1;!P(n-i);++i)++r;
			printf("%d\n",r);
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

long long gcd( long long a ,long long b )
{
	return b ? gcd( b ,a % b ) : a ;
}

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


int main()
{
	long long a ,b ;

	while( scanf( "%lld %lld" ,&a ,&b ) != EOF )
	{

		printf( "%lld %lld\n" ,gcd( a ,b ) ,lcm( a ,b ) ) ;
	}

	return 0 ;
}

Measured memory_bytes: 596
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

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

	vector< vector< int > > vs(n);
	rep (i , m) {
		int a;
		int b;
		cin >> a >> b;
		a--;b--;
		vs[a].push_back(b);
		vs[b].push_back(a);
			
	}

	vector<int> ns(n);

	iota(ns.begin(), ns.end(), 0);

	int ans = 0;
	do {
		if (ns[0] != 0) {
			continue;
		}
		bool is_ok = true;
		rep(i, n - 1) {

			int cur = ns[i];
			int next = ns[i + 1];
			bool ok = false;
			for(int v : vs[cur]) {
				if (v == next) {
					ok = true;
					break;
				}
			}
			
			if (ok == false) {
				is_ok = false;
				break;
			}

		}
		if (is_ok) {
			ans++;
		}
	} while(next_permutation(ns.begin(), ns.end()));
	cout << ans<< endl;

	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sumvec(vector<S>&a){return accumulate(all(a),S());}
template<class S>S maxvec(vector<S>&a){return *max_element(all(a));}
template<class S>S minvec(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}


int main(void){
  	cin.tie(0);
  	ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    if(s[0]=='S')puta("Cloudy");
    if(s[0]=='C')puta("Rainy");
    if(s[0]=='R')puta("Sunny");
    
}


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

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

    string s, t;
    cin>>s>>t;
    int ans = 0;
    for(int i=0; i<s.length(); i++)
        if(s[i] != t[i])
            ans++;
    cout<<ans<<endl;
    // int t;
    // cin>>t;
    // while(t--)
    // {
        
    // }
}

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

#define FOR(k,m,n) for(int(k)=(m);(k)<(n);(k)++)
#define REP(k,n) FOR((k),0,(n))

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

    for (int i = 1; i <= S.size(); i++) {
        char c = S[i - 1];
        if (i % 2 == 0) {
            if (c != 'L' && c != 'U' && c != 'D') {
                printf("No\n");
                return 0;
            }
        } else {
            if (c != 'R' && c != 'U' && c != 'D') {
                printf("No\n");
                return 0;
            }
        }
    }

    printf("Yes\n");
    return 0;
}


/*
 * Local Variables:
 * compile-command: "CXXFLAGS='-std=c++14' make main"
 * End:
 */


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


int main(){
 int k, i,n=0, a[1000];
int sum =0;
cin >> n>> k ;
for (int i = 0; i < n; i++) {
        cin >> a[i] ;
}
sort(a,a+n);
for (int i= 0; i < k; i++) {
        sum +=  a[i] ;
}
cout << sum;
	return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int n,m,a[100001],ans;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+1+n,greater<int>());
	for(int i=1;i<=m;i++)
		ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int n, k[15], s = 1, ans = 1;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
		s *= 3;
		if (k[i] % 2 == 0) ans *= 2;
	}
	cout << s - ans << endl;
}

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

typedef long long LL;

int N;
LL Ans;

map<LL,int> Cnt;

int main(){
	int i,x;
	LL s=0;
	scanf("%d",&N);
	Cnt[0]++;
	while(N--){
		scanf("%d",&x),s+=x;
		Ans+=Cnt[s];
		Cnt[s]++;
	}
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 12672
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    string s;
    cin >> s;
    bool f = true;
    for(int i = 0; i < (int) s.size(); i+= 2){
        if(s[i] == 'L')f = false;
    }
    for(int i = 1; i < (int) s.size(); i+= 2){
        if(s[i] == 'R') f = false;
    }
    if(f)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
 
 
def main():
    H, W = map(int, input().split())

    S = []
    for _ in range(H):
        S.append(list(input()[:-1]))
    
    U = [[0]*W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j]=='#':
                continue
            if i==0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j] + 1

    D = [[0]*W for _ in range(H)]
    for i in reversed(range(H)):
        for j in range(W):
            if S[i][j]=='#':
                continue
            if i==H-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j] + 1
    
    L = [[0]*W for _ in range(H)]
    for j in range(W):
        for i in range(H):
            if S[i][j]=='#':
                continue
            if j==0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1] + 1

    R = [[0]*W for _ in range(H)]
    for j in reversed(range(W)):
        for i in range(H):
            if S[i][j]=='#':
                continue
            if j==W-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1] + 1

    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3)
    print(ans)

 
if __name__ == '__main__':
    main()


Measured memory_bytes: 306184
#include <stdio.h>

#define NUM 3

int main(void){
	int a, b, c;
	int hours, minutes, seconds;
	int i;

	scanf("%d %d %d", &a, &b, &c);
	
	if(a < b && b < c){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <deque>

using namespace std;

long long cnt = 0;
deque<int> G;

void insertionSort(int A[], int N, int g) {
    for (int i = g; i < N; i++) {
        int v = A[i];
        int j = i - g;
        while (j >= 0 && A[j] > v) {
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void shellSort(int A[], int N) {
    for (int h = 1; ; ) {
        if (h > N) {
            break;
        }
        G.push_front(h);
        h = 3*h + 1;
    }

    for (auto g : G) {
        insertionSort(A, N, g);
    }
}

int main() {
    int N;
    cin >> N;

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

    shellSort(A, N);

    cout << G.size() << endl;

    for (int i = 0; i < G.size(); i++) {
        if (i > 0) {
            cout << " ";
        }
        cout << G[i];
    }
    cout << endl;

    cout << cnt << endl;

    for (auto a: A) {
        cout << a << endl;
    }

    return 0;
}

Measured memory_bytes: 6992
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

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

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

ll N, M, K, i, j, k, l, ans, cnt = 0;

int main(){
    //cin >> ;
    //cout << ans << endl;
    ll A, B, C, K, tmp;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> K;

    tmp = (A + B) - K;
    if(A > K){
        ans = K;
    }
    else if(tmp >= 0){
        ans = A;
    }else{
        ans = A + tmp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
n = gets.to_i
t = [], x = [], y = []
n.times do |i|
	t[i], x[i], y[i] = gets.split.map(&:to_i)
end
n.times do |i|
	if x[i]+y[i] > t[i]
		puts "No"
		exit
	end

	if (x[i]+y[i])%2 != 0 && t[i]%2 == 0
 		puts "No"
		exit
	end

	if (x[i]+y[i])%2 == 0 && t[i]%2 != 0
		puts "No"
		exit
	end
end

puts "Yes"

Measured memory_bytes: 4324
import collections

n = int(input())
a = [int(i) for i in input().split()]

d = collections.defaultdict(int)

for i in a:
    i_ = i // 400
    if i_ >= 8:
        i_ = 8
    d[i_] += 1

if 8 in d:
    min_ = max(len(d) - 1, 1)
    max_ = len(d) + d[8] - 1

else:
    min_ = len(d)
    max_ = len(d)

print(min_, max_)

Measured memory_bytes: 3316
n = int(input())
peer = [[] for _ in range(n)]
for _ in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  peer[a].append(b)
  peer[b].append(a)
edge = [0 for _ in range(n)]
seen = [0 for _ in range(n)]
seen[0] = 1
now = [0]
while now:
  last = now
  now = []
  for x in last:
    for y in peer[x]:
      if seen[y] == 0:
        edge[y] = edge[x] + 2**(y-1)
        seen[y] = 1
        now.append(y)

def count1(x):
  y = bin(x)
  z = 0
  l = len(y)
  for li in range(l):
    if y[li] == '1':
      z += 1
  return z

def count2(x):
  z = 0
  l = len(x)
  for li in range(l):
    if x[li] == '1':
      z += 1
  return z


m = int(input())
restr = []
for _ in range(m):
  u,v = map(int,input().split())
  u -= 1
  v -= 1
  restr.append(edge[u]^edge[v])
#print(edge)
#print(restr)

ans = 0
for i in range(2**m):
  b = bin(i)[2:]
  time = '0' * (m-len(b)) + b
  tmp = 0
  for j in range(m):
    if time[j] == '1':
      tmp |= restr[j]
  if count2(time) % 2 == 0:
    ans += 2**(n-1-count1(tmp))
    #print('+',count2(time),time,count1(tmp),ans,bin(tmp))
  else:
    ans -= 2**(n-1-count1(tmp))
    #print('-',count2(time),time,count1(tmp),ans,bin(tmp))
#print(restr)
print(ans)

Measured memory_bytes: 45912
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

ll h, w;
ll d[103][103];
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> h >> w;
  vector<string> s(h);
  for(int i = 0; i < h; i++) cin >> s[i], s[i] += '#';
  using P = tuple<int, int>;
  queue<P>q;
  const int inf = 1e9;
  for(int i = 0; i <= h; i++) for(int j = 0; j <= w; j++) for(int k = 0; k < 3; k++) d[i][j] = inf;
  d[0][0] = 0;
  q.emplace(0, 0);
  if(s[0][0] == '#') {
    d[0][0] = 1;
  }
  while(q.size()) {
    ll x, y;
    tie(x,y) = q.front();
    q.pop();
    for(int dx = 0; dx < 2; dx++) for(int dy = 0; dy < 2; dy++) {
      if(!dx && !dy) continue;
      if(dx && dy) continue;
      int nx = x+dx;
      int ny = y+dy;
      if(nx==h||ny==w) continue;
      int nd = d[x][y] + (s[nx][ny] != s[x][y] && s[x][y] == '.');
      if(nd < d[nx][ny]) {
        d[nx][ny] = nd;
        q.emplace(nx, ny);
      }
    }
  }

  ll ans = d[h-1][w-1];

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF ((int)1<<50)
signed main(){
    int n;
    cin>>n;
    vector<int> vec;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        vec.push_back(t);
    }
    int ans=INF;
    for(int j=0;j<2;j++){
        bool f=j;
        int t=0;
        int sum=0;
        for(int i=0;i<vec.size();i++){
            sum+=vec[i];
            if(!f){
                if(sum<=0){
                    t+=1-sum;
                    sum=1;
                }
                f=true;
            }
            else{
                if(sum>=0){
                    t+=1+sum;
                    sum=-1;
                }
                f=false;
            }
        }
        ans=min(ans,t);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1400
from itertools import*
n,c,*L=map(int,open(0).read().split())
acc=[a-x for x,a in zip(L[::2],accumulate(L[1::2]))]
acc_max=list(accumulate([0]+acc,max))
R=L[::-1]
rev=[a-(c-x) for x,a in zip(R[1::2],accumulate(R[::2]))]
rev_max=list(accumulate([0]+rev,max))
p=max(rev_max[n-i-1]+a-b for i,(a,b) in enumerate(zip(acc,L[::2])))
q=max(acc_max[n-i-1]+a-(c-b) for i,(a,b) in enumerate(zip(rev,R[1::2])))
r=max(0,acc_max[-1],rev_max[-1])
print(max(p,q,r))

Measured memory_bytes: 25588
#include <stdio.h>
int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a < b){
        if(b < c){
          puts("Yes");
            }else{
               puts("No");
     }}else{
        puts("No");
}
    return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define H_MAX 100
#define W_MAX 100
#define WALL '#'

constexpr int INF = 1e9;

using std::make_pair;
using std::pair;
using std::queue;
using std::vector;

// grid
using Grid = vector<std::string>;
// gridの左上を(0,0)として(↓,→)の座標
using YX = pair<int, int>;

const vector<YX> MOVES = {
    make_pair(1, 0),  // 下へ
    make_pair(0, 1)   // 右へ
};

// (H_MAX+2) * (W_MAX+2) のvectorで距離を表す。INFで初期化
// 2に意味はない。0でも良い
vector<vector<int>> d(H_MAX + 2, vector<int>(W_MAX + 2, INF));

/**
 * inputs: int, int, Grid, queue<YX>, YX, (int)
 *      h:高さ，w:幅，m:グリッド，starts:始点リスト，goal:終点，
 *      (c:始点でのコスト(=0))
 * outputs: pair<int, queue<YX>>
 *      (コスト(到達不可能時は-1)，壁リスト)
 */
using BfsRes = pair<int, queue<YX>>;
BfsRes bfs(int h, int w, Grid m, queue<YX> starts, YX goal, int c = 0) {
    // 壁リスト
    queue<YX> next;

    // TODO: ここ定数倍重い
    queue<YX> que;
    while (!starts.empty()) {
        YX s = starts.front();
        starts.pop();

        que.push(s);
        // 始点のコストは c(=0)
        if (d.at(s.first).at(s.second) > c) {
            d.at(s.first).at(s.second) = c;
        }
    }

    while (!que.empty()) {
        YX prev = que.front();
        que.pop();
        int py            = prev.first;
        int px            = prev.second;
        bool prev_is_wall = m.at(py).at(px) == WALL;
        int prev_cost     = d.at(py).at(px);  // == c

        // 下右で，通路->壁をせずに行けるところを見ていく
        for (const YX &dm : MOVES) {  // dm: 微小なmove
            int y = py + dm.first;
            int x = px + dm.second;
            if (y >= h || x >= w) continue;

            YX curr           = make_pair(y, x);
            bool curr_is_wall = m.at(y).at(x) == WALL;
            bool pass_to_wall = (!prev_is_wall && curr_is_wall);
            int curr_cost     = prev_cost + (pass_to_wall ? 1 : 0);

            // 最短距離を更新できないなら訪問しない
            if (d.at(y).at(x) <= curr_cost) {
                if (curr == goal) return make_pair(curr_cost, next);
                continue;
            }

            // 通路→壁ならcost++
            if (pass_to_wall) {
                d.at(y).at(x) = curr_cost;  // == c+1
                next.push(curr);
                continue;
            }

            if (curr == goal)
                return make_pair(curr_cost, next);  // curr_cost == c

            // 最短距離を更新してqueに突っ込む
            d.at(y).at(x) = curr_cost;  // == c
            que.push(curr);
        }
    }

    return bfs(h, w, m, next, goal, c + 1);
}

void agc043_a();

//-----------------------------------------------------------------------main()-----------
int main(void) {
    agc043_a();
    return 0;
}

void agc043_a() {
    int h, w;
    std::cin >> h >> w;

    Grid s(h);
    for (int i = 0; i < h; ++i) std::cin >> s.at(i);

    queue<YX> starts;
    starts.push(make_pair(0, 0));

    int c   = (s.at(0).at(0) == WALL);
    int ans = bfs(h, w, s, starts, make_pair(h - 1, w - 1), c).first;

    std::cout << ans << std::endl;
    return;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	char ch; cin >> ch;
	if ('a' <= ch && ch <= 'z') {
		ch = 'a';
	}
	else {
		ch = 'A';
	}
	cout << ch << "\n";

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(3 * N);
  rep(i, 3 * N) cin >> a[i];
  ll sum = 0;
  sort(all(a), greater<int>());
  rep(i, N) sum += a[2 * i + 1];
  cout << sum << endl;
}

Measured memory_bytes: 1408
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int n;
    cin>>n;
    V<ll> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    ll ans=a[0];
    for(int i=1;i<n;i++)ans=lcm(ans,a[i]);
    cout<<ans<<"\n";
}



Measured memory_bytes: 3236
import java.util.Scanner;
class Main {
	static final int MAX = 200000;
	public static void main(String[] args) {
		int[] R = new int[MAX];
		int n;
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		for(int i = 0;i<n;i++) R[i] = in.nextInt();
		
		int maxv = R[1]-R[0];
		int minv = R[0];
		for(int i = 1;i<n;i++){
			if(maxv < R[i] - minv) maxv = R[i]-minv;	
			if(minv>R[i]) minv = R[i];
		}
		System.out.println(maxv);
	}
}

Measured memory_bytes: 101832
use std::io;
use std::str::FromStr;
use std::collections::BinaryHeap;

type Pair = (u64, u64);

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_tuple_three() -> (u64, u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1], vec[2])
}

fn main() {
    let (n, m, q) = input_tuple_three();
    let mut regions: Vec<Vec<u64>> = vec![Vec::new(); n as usize];
    let mut sum: Vec<Vec<u64>> = vec![Vec::new(); n as usize];
    for _ in 0..m {
        let (l, r) = input_tuple();
        regions[l as usize - 1].push(r - 1);
    }
    for i in 0..n as usize {
        let mut queue: BinaryHeap<i64> = BinaryHeap::new();
        for j in &regions[i] {
            queue.push(0 - *j as i64);
        }
        let mut prev = 0;
        for j in 0..n {
            if queue.is_empty() || 0 - j as i64 > *queue.peek().unwrap() {
                sum[i].push(prev);
                continue;
            }
            while !queue.is_empty() && 0 - j as i64 <= *queue.peek().unwrap() {
                queue.pop();
                prev += 1;
            } 
            sum[i].push(prev);
        }
    }
    // println!("{:?}", sum);

    for _ in 0..q {
        let (l, r) = input_tuple();
        let mut ans = 0;
        for j in (l-1)..n {
            ans += sum[j as usize][r as usize - 1];
        }
        println!("{}", ans);
    }
}


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

using namespace std;

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

const int INF = 1e9 + 1;
const int MAX_N = 1e5 + 1;

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

  int a, b;
  cin >> a >> b;
  int ans = max(max(a + b, a - b), a * b);

  cout << ans << endl;

  return 0;
}



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

int main(){
    string s,t;
    cin>>s >>t;
    int n=(int)s.size(),m=(int)t.size();
    
    if(n<m){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    
    vector<string> ans;
    
    for(int i=0;i<n-m+1;i++){
        bool ok = true;
        string u = s;
        for(int j=0;j<m;j++){
            if(u[i+j]!='?'&&t[j]!=u[i+j]){
                ok = false;
                break;
            }
            u[i+j]=t[j];
        }
        if(ok){
            for(int k=0;k<n;k++){
                if(u[k]=='?')u[k]='a';
            }
            ans.push_back(u);
        }
    }
    
    if(ans.empty()){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    
    sort(ans.begin(),ans.end());
    
    cout<<ans[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
int main(){
    int N,M;
    int count[50] = {};
    cin >> N >> M;
    REP(i,M){
        int a,b;
        cin >> a >> b;
        count[a-1]++;
        count[b-1]++;
    }
    REP(i,N) cout << count[i] << endl;
    return 0;
}


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

using namespace std;

char a[100100];
int u;

int main () {
    cin >> a[0];
    u = a[0]; u++;
    a[0] = u;
    cout << a[0];
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int N, M;
int Q, A[1 << 18], B[1 << 18], C[1 << 18], D[1 << 18];
int Answer = 0;

void dfs(int pos, int dep, vector<int> P) {
	if (pos == N) {
		int sum = 0;
		for (int i = 1; i <= Q; i++) {
			if (P[B[i] - 1] - P[A[i] - 1] == C[i]) sum += D[i];
		}
		Answer = max(Answer, sum);
		return;
	}

	for (int i = dep; i <= M; i++) {
		vector<int>PP = P; PP.push_back(i);
		dfs(pos + 1, i, PP);
	}
}

int main() {
	cin >> N >> M >> Q;
	for (int i = 1; i <= Q; i++) cin >> A[i] >> B[i] >> C[i] >> D[i];
	dfs(0, 1, vector<int>{});
	cout << Answer << endl;
	return 0;
}

Measured memory_bytes: 3572
#include<stdio.h>
int main()
{
int A,M;
scanf("%d %d",&A,&M);
if(A+M==3)
{
printf("3\n");
}
else if(A+M==5)
{
 printf("1\n");
}
else if(A+M==4)
{
 printf("2\n");
}
return 0;
}

Measured memory_bytes: 1588
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
#include <cassert>
#include <complex>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1e8;

int calc(vector<P> a){
    sort(a.begin(),a.end());
    int res = inf;
    int py = -2*inf;
    for(int i=1;i<a.size();i++){
        if(a[i-1].second==0 && a[i].second!=0){
            res = min(res,a[i].first-a[i-1].first);
        }
    }
    return res;
}

int calc(map<int,vector<P>> &mp){
    //最小を計算
    int res = inf;
    for(auto p:mp){
        res = min(res,calc(p.second));
    }
    return res;
}

int main() {
    int n;
    cin>>n;
    vector<int>x(n),y(n),dir(n);
    for(int i=0;i<n;i++){
        char d;
        cin>>x[i]>>y[i]>>d;
        if(d=='U')dir[i]=0;
        if(d=='R')dir[i]=1;
        if(d=='D')dir[i]=2;
        if(d=='L')dir[i]=3;
    }
    int ans = inf;
    for(int rotate = 0;rotate<4;rotate++){
        {
            //UD
            map<int,vector<P>>mp;
            for(int i=0;i<n;i++){
                if(dir[i]!=0 && dir[i]!=2)continue;
                mp[x[i]].emplace_back(y[i],dir[i]);
            }
            ans = min(ans,calc(mp)*5);
        }
        {
            //UR
            map<int,vector<P>>mp;
            for(int i=0;i<n;i++){
                if(dir[i]!=0 && dir[i]!=1)continue;
                mp[x[i]+y[i]].emplace_back(y[i],dir[i]);
            }
            ans = min(ans,calc(mp)*10);
        }
        //回転操作
        for(int i=0;i<n;i++){
            int px = x[i],py = y[i];
            x[i]=py;
            y[i]=-px;
            dir[i] = (dir[i]+1)%4;
        }
    }
    if(ans==inf)cout<<"SAFE"<<endl;
    else cout<<ans<<endl;
}


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

using namespace std;
int main()
{
    int n,sum=0;
    cin>>n;
    int temp=n;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
   //12 cout<<sum<<endl;
    if(temp%sum==0)cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a,b,k;
    cin >> a >> b >> k;
    for(int i = 100; i > 0; i--){
        if(a%i == 0 && b % i == 0)k--;
        if(k == 0){
            cout << i << endl; 
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
typedef pair<int,int>pii;
int n,a[N],b[N],i;
long long su;
priority_queue<pii>q;
inline int lst(int x){
	return x==1?n:x-1;
}
inline int nxt(int x){
	return x==n?1:x+1;
}
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",a+i);
	for(i=1;i<=n;++i)scanf("%d",b+i),q.push(pii(b[i],i));
	for(;!q.empty();){
		int u=q.top().second;q.pop();
		if(b[u]<a[u]){
			su=-1;break;
		}
		int z=b[lst(u)]+b[nxt(u)];
		if(b[u]%z>a[u]){
			su+=b[u]/z;
			b[u]%=z;q.push(pii(b[u],u));
			if(b[u]>=b[lst(u)] && b[u]>=b[nxt(u)]){
				su=-1;break;
			}
		}else if((b[u]-a[u])%z){
			su=-1;break;
		}else su+=(b[u]-a[u])/z,b[u]=a[u];
	}
	printf("%lld\n",su);
}

Measured memory_bytes: 4724
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>
using namespace std;

#define ll long long

void solve()
{

    double A, B, N;
    cin >> A >> B >> N;
    double x = B - 1 < N ? B - 1 : N;
    ll result;
    result = floor(A * x / B) - A * floor(x / B);

    cout << result << endl;
    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n;
	cin >> n;
	vl v(n);
	rep(i, n) cin >> v[i];
	sort(all(v));
	vl sum(n);
	sum[0] = v[0];
	REP(i, 1, n) sum[i] += v[i] + sum[i-1];
	int tmp = 0;
	rep(i, n -1) {
		if(sum[i] * 2LL < v[i+1]) tmp = 0;
		else tmp++;
	}
	cout<<tmp+1<<endl;
}


Measured memory_bytes: 1920
def main():
    N = int(input())
    ss = list(map(int, input().split()))

    if N <= 1:
        print(0)
        return
    a = ss.pop(0)
    count = 0
    for b in ss:
        if a == b:
            count += 1
            a = -1
        else:
            a = b
    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
def examC():
    N, M = LI()
    if N-M//2>=0:
        ans = M//2
    else:
        ans = N + (M-N*2)//4
    print(ans)
    return

def examD():
    N = I()
    S = SI()
    for i1,i2 in [[0,0],[0,1],[1,0],[1,1]]:
        flag = True
        sheep = [1]*N
        sheep[0] = i1
        sheep[1] = i2
        for j in range(1,N-1):
            if S[j]=="o":
                cur = 1
            else:
                cur = 0
            sheep[j+1] = (sheep[j]^cur)^sheep[j-1]
        if S[-1] == "o":
            cur = 1
        else:
            cur = 0
        if sheep[0]!=(sheep[-1] ^ cur) ^ sheep[-2]:
            flag = False
        if S[0] == "o":
            cur = 1
        else:
            cur = 0
        if sheep[1]!=(sheep[0] ^ cur) ^ sheep[-1]:
            flag = False
        if flag:
            ans = ""
            for i in sheep:
                if i==1:
                    ans += "S"
                else:
                    ans += "W"
            print(ans)
            return
    print(-1)
    return

def examE():
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()

"""

"""

Measured memory_bytes: 5232
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int a,b,m;
	cin >> a >> b >> m;
	vector<int> A(a), B(b);
	REP(i,a) cin >> A[i];
	REP(i,b) cin >> B[i];
	int ans = *min_element(ALL(A)) + *min_element(ALL(B));
	REP(i,m){
		int x,y,c;
		cin >> x >> y >> c;
		x--, y--;
		int tmp = A[x] + B[y] - c;
		ans = min(ans, tmp);
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 1024
#!/usr/bin/env python3

n, k, q = list(map(int, input().split()))

score = [k for _ in range(n)]

count = [0 for _ in range(n)]
for i in range(q):
    a = int(input())
    count[a-1] += 1

for i in range(n):
    score = k+count[i]-q
    if score >= 1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi   = vector<int>;
using vll  = vector<ll>;
using vc   = vector<char>;
using vvll  = vector<vll>;
using vvi  = vector<vi>;
using vvc  = vector<vc>;
using vb   = vector<bool>;
using vvb  = vector<vb>;
using pii  = pair<int,int>;
using vpii = vector<pii>;


int main() {
    int N, M; cin >> N >> M;
    int tmp_min=1, tmp_max=N;
    vector<pii> ID;
    for (int i = 0; i < M; i++) {
        int tmpL, tmpR; cin >> tmpL >> tmpR;
        ID.push_back(make_pair(tmpL, tmpR));
    }
    sort(ID.begin(), ID.end());


    for (auto x : ID) {
        int tmpL, tmpR;
        tie(tmpL, tmpR) = x;
        if (tmp_min < tmpL) tmp_min = tmpL;
        if (tmpR < tmp_max) tmp_max = tmpR;
    }
    if (tmp_max < tmp_min) cout << 0 << endl;
    else    cout <<  tmp_max - tmp_min +1 << endl;

}

Measured memory_bytes: 4240
#include<cstdio>
#include<iostream>

using namespace std;

int n, A[50];

int solve(int i, int m){
    if (m==0) return 1;
    if (i>=n) return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main(int argc, char const *argv[])
{
    int q, M, i;

    cin >> n;
    for(i=0; i<n; i++) scanf("%d", &A[i]);
    cin >> q;
    for (int i = 0; i < q; ++i){
        scanf("%d", &M);
        if(solve(0,M)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<utility>
#include<fstream>
#include<queue>
#include <iomanip>
#include<numeric>
#include<set>
using namespace std;
typedef long long ll;
#define rep(i,k) for(i=0;i<k;i++)
#define P pair<ll,ll>
ll mod = 1000000007;
P p[200005];

ll i, b[100005], c, k, j, n, m, z = 0, mi = 0,s,t;
ll a[100005] = {};
vector<ll> v[30];
//string s;
char ca[10000];
priority_queue<ll> q;
int main() {
	cin >> n>>m;
	if (n == 1 || m == 1){
		cout << 1;
		return 0;}


	i = 3;
	k = min(n, m);
	t = max(n, m);
	if (k % 2 == 0 && t % 2 == 0)z++;
	while (k % 2 == 0)k = (k >> 1);
	for (i = 3; i * i < k;i+=2 ) {
		if (k%i==0 && t % i == 0)z++;
		while (k % i == 0) 	k = k / i;
	}
	if(k!=1&&t%k==0)z++;
	z++;
	cout << z;

	return 0;
}

Measured memory_bytes: 256
import bisect
 
n,maxw = map(int , input().split())
data1 = [[0,0]] #data1enu[i]:iのbitが立ってる品物の価値、重さの総和
data2 = [[0,0]]
nn = n // 2

for i in range(nn):
    v,w = map(int , input().split())
    sz = len(data1)
    for j in range(sz):
        ppp = data1[j][:]
        ppp[0] += w
        ppp[1] += v
        data1.append(ppp)

for i in range(n-nn):
    v,w = map(int , input().split())
    sz = len(data2)
    for j in range(sz):
        ppp = data2[j][:]
        ppp[0] += w
        ppp[1] += v
        data2.append(ppp)

data2.sort()
maxx = 0
ss = len(data2)
for i in range(ss):
    maxx = max(maxx , data2[i][1])
    data2[i][1] = maxx
ans = 0
ss = len(data1)
for i in range(ss):
    ww , vv = data1[i]
    if (ww > maxw) : continue
    amari = maxw - ww
    ans = max (ans , vv + data2[bisect.bisect_right(data2, [amari , float('inf')])-1][1])

print(ans)



Measured memory_bytes: 358524
import java.util.*;

import static java.lang.System.*;

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

        for (int i = 0; i < n; i++) {
            String s = sc.next();
            for (int j = 0; j < s.length(); j++) {
                char c = s.charAt(j);
                cnt[i][c - 'a']++;
            }
        }

        int[] commonCnt = new int[26];
        for (int j = 0; j < 26; j++) {
            int min = Integer.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                min = Math.min(cnt[i][j], min);
            }
            commonCnt[j] = min;
        }

        for (int j = 0; j < 26; j++) {
            for (int i = 0; i < commonCnt[j]; i++) {
                out.print((char) ('a' + j));
            }
        }
        out.println();
    }
}

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

int main() {
    int N, K; cin >> N >> K;
    double pr = 0;
    for (int i = 1; i <= N; i++) {
        int point = i;
        double t = 1.0 / N;
        while (point < K) {
            point *= 2;
            t /= 2.0;
        }
        pr += t;
    }
    cout << setprecision(16) << pr << endl;
}

Measured memory_bytes: 256
/*input
1333333333
*/

#include <bits/stdc++.h>
#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() {
  ll x;
  cin >> x;
  ll m = 100;
  for (int i = 1; i < 1001001001; ++i) {
    m = m+(m/100);
    if (m >= x) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3636
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

trait ChMinMax {
    fn chmin(&mut self, other: Self);
    fn chmax(&mut self, other: Self);
}
impl<T> ChMinMax for T
where
    T: PartialOrd,
{
    fn chmin(&mut self, other: Self) {
        if *self > other {
            *self = other
        }
    }
    fn chmax(&mut self, other: Self) {
        if *self < other {
            *self = other
        }
    }
}

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, x: usize, t: usize);
    println!("{}", t * (n / x + if n % x == 0 { 0 } else { 1 }));
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2136
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define mp make_pair

void print(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cout<<a[i]<<' ';
    cout<<endl;
}

const ll p = 1e9 + 7;

int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    s = s%p;
    if (s<0) s+=p; 
    return s;
}

const ll INF = 100000000000000000;

int n, m;
struct st
{
    int s;
    int f;
    ll cost;
};


int f(char a, char b, char c)
{
    if (a==b&&b==c) return 0;
    if (a==b&&b!=c) return 1;
    if (a==c&&b!=c) return 1;
    if (a!=b&&b==c) return 1;
    if (a!=b&&b!=c&&c!=a) return 2;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    string a, b, c;
    cin>>n>>a>>b>>c;
    int result = 0;
    for (int i = 0; i<n; i++) result+=f(a[i], b[i], c[i]);
    cout<<result;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	string s;
	cin >> s;
	cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No");
	return 0;
}


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

void initialize();
int isEnpty();
int isFull();
void push(int);
int pop();

int top=0;
int array[100];
char s[100];

int main(void){
  int x;

  int i=0;

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){

      int temp1 = pop();
      int temp2 = pop();
      int temp3 = temp1 + temp2;
      push(temp3);

    } else if ( s[0] == '-' ){
      int temp1 = pop();
      int temp2 = pop();
      int temp3 = temp2 - temp1;
      push(temp3);

    } else if ( s[0] == '*' ){
      int temp = pop() * pop();
      push(temp);

    } else {
      x = atoi(s);

      //printf("%d\n", x);
      push(x);

    }
  }

  printf("%d\n", array[top]);




  return 0;



}


void initialize(){
  top = 0;
}

//topが0ならば0をかえし、そうでないなら1を返す
int isEnpty(){
  if(top==0){
    return 0;
  }
  else{
    return 1;
  }
}


//topがMAX以上ならば0をかえし、そうでないなら1を返す
int isFull(){
  if(top >= 100){
    return 0;
  }
  else{
    return 1;
  }

}

void push(int a){
  if(isFull()==0){
    printf("error\n");
    return;
  }
  top++;
  array[top]=a;
}

int pop(){
  if(isEnpty()==0){
    printf("error\n");
    return 0;
  }
  top--;
  return array[top+1];

}



Measured memory_bytes: 2092
from math import gcd
import sys

N, M = map(int, input().split())
A = list(map(int, input().split()))

lcm = 1
for a in A:
    gcd_ = gcd(lcm, a//2)
    lcm = lcm * (a // 2 // gcd_)
for a in A:
    if (lcm // (a // 2)) % 2 == 0:
        print(0)
        sys.exit()

print(M // lcm - M // (2 * lcm))


Measured memory_bytes: 84956