akhauriyash/Code-Regression huggingface dataset:
from collections import deque

inf = 10**10

h,w = map(int,input().split())
field = [input() for _ in range(h)]

length = [[inf for j in range(w)]for i in range(h)]
visited = [[0 for j in range(w)]for i in range(h)]

move = [[-1,0],[1,0],[0,-1],[0,1]]

que = deque([])
que.append([0,0])
length[0][0] = 0
visited[0][0] = 1

white = 0

for i in range(h):
    white += field[i].count(".")

while que:
    y,x = que.popleft()

    for i,j in move:
        ny,nx = y+i,x+j

        if ny < 0 or ny >= h or nx < 0 or nx >= w:
            continue
        elif field[ny][nx] == "#":
            continue
        elif visited[ny][nx] == 1:
            continue
        
        visited[ny][nx] = 1
        que.append([ny,nx])
        length[ny][nx] = length[y][x] + 1

if length[h-1][w-1] == inf:
    print(-1)
else:
    print(white-(length[h-1][w-1]+1))

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

#include <cstring>
#include <string>

#include <cmath>
#include <algorithm>

#include <vector>
#include <queue>

#include <utility>
#include <map>

// #include <bits/stdc++.h>

#define LL long long
#define vi vector<int>
#define set0(x) memset((x),0,sizeof((x)))
#define set1(x) memset((x),1,sizeof((x)))
#define setmin(x) memset((x),-1,sizeof((x)))
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second

#define MOD 1000000007

using namespace std;

int comp(pair<LL,LL> a, pair<LL,LL> b){
	return a.fi/a.se>b.fi/b.se;

}
int main() {
	ios_base::sync_with_stdio(0);
	//quarter=0.25 half=0.5 single=1 double=2 liters
	pair<LL,LL> x[5];
	LL n;
	LL ans=0;
	x[1].se=1;
	x[2].se=1;
	x[3].se=1;
	x[4].se=2;
	for(int i=1;i<=4;i++){
		cin>>x[i].first;
	}
	cin>>n;
	x[1].first*=4;
	x[2].fi*=2;
	sort(x+1,x+5,comp);
//	for(int i=1;i<=4;i++) {
//		cout<<x[i].first<<" "<<x[i].second<<endl;
//	}
	int z=4;
	while(n>0){
		if(x[z].se<=n){
			if(x[z].se==2) {
				if(n%2==1){
					ans+=n/2*x[z].first;
					n=1;
					z--;
				} else{
					ans+=n/2*x[z].first;
					break;
				}
			} else {
				ans+=n*x[z].first;
				break;
			}
		} else z--; 
	}
	
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int i = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int i = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int i = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    int n; cin >> n;
    int cnt = 0;
    rep(i,n){
        int d, e; cin >> d >> e;
        if(d == e){
            ++cnt;
            if(cnt == 3){
                yes();
                return 0;
            }
        }
        else cnt = 0;
    }
    no();
    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 3648
use io::*;
use std::*;

fn solve(N: i64) {
    let answer: i64 = (1..=N).filter(|&x| x % 3 != 0 && x % 5 != 0).sum();
    println!("{}", answer);
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let mut N: i64;
    N = scanner.next();
    solve(N);
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
}


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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
#define int long long

string solve(){
    string s, t;
    cin >> s >> t;
    int n = (int)s.length(), m = (int)t.length();
    
    for(int i = n-m; i >= 0; i--){
        bool ok = true;
        rep(j,m){
            if(s[i+j] == '?') continue;
            if(s[i+j] != t[j]) ok = false;
        }
        if(ok){
            rep(j,n){
                if(s[j] == '?') s[j] = 'a';
                if(i <= j && j < i+m) s[j] = t[j-i];
            }
            return s;
        }
    }
    return "UNRESTORABLE";
}

signed main(){
    cout << solve() << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
 
class Program {
	static void Main (string[] args) {
		string[] str = Console.ReadLine().Split(' ');
    	int a = int.Parse(str[0]);
    	int b = int.Parse(str[1]);
    	int k = int.Parse(str[2]);
    
    	int sml = (a > b) ? b : a;
    	List<int> nums = new List<int>();
    	for (int cnt = 1; cnt <= sml; cnt++) {
        	if (a % cnt == 0 && b % cnt == 0) {
            	nums.Add(cnt);
        	}
        }
    	int index = nums[nums.Count - k];
    	Console.WriteLine(index);
	}
}

Measured memory_bytes: 11092
/*@sh*/
#include<bits/stdc++.h>
using namespace std;
#include<cstdio>
#define pi 3.141592653589
#define pb push_back
#define ld long double
#define rem 1000000007
#define F first
#define S second
#define pii pair<long long,long long>
#define el "\n"
#define sp " "
typedef long long ll;
ll  p = 1000000007;
ll Pow(ll,ll,ll);
ll Pow(ll a,ll b,ll p){
	if(b==0) return 1;
	return !(b%2) ? (Pow(a,b/2,p)%p)*(Pow(a,b/2,p)%p)%p : (a%p)*(Pow(a,b-1,p))%p;
}   
main()
{ 
	// fast io
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);ll i; 
	string s,t;
	cin>>s>>t;
	ll m=s.size(),n=t.size();
    ll L[m+1][n+1];
	for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (s[i-1] == t[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     }
}
	ll index = L[m][n]; 
	//cout<<index<<el;
	char lcs[index+1];
	lcs[index]='\0';
   	i = m;ll j = n; 
   while (i > 0 && j > 0) 
   { 
      if (s[i-1] == t[j-1]) 
      { 
          lcs[index-1] = s[i-1];
          i--; j--; index--; 
      }
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
   cout<<lcs<<el;
}


Measured memory_bytes: 70656
import java.io.*;
import java.util.Arrays;
class Main{
	public static void main(String[] args) throws IOException {
		int i,tmp;
		int[] n = new int[990];
		String[] str = new String[990];
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		str = in.readLine().split(" ");
		for(i=0;i<1;i++){
			n[i] = Integer.parseInt(str[i]);
		}
		for(i=3;i<=n[0];i++){
			tmp = i;
			if(tmp%3==0){
				System.out.print(" "+i);
				continue;
			}
			else{
				while(tmp!=0){
					if(tmp%10==3){
						System.out.print(" "+i);
						break;
					}
					tmp/=10;
				}
			}
		} 
		System.out.println();
		System.out.flush();
	}
}

Measured memory_bytes: 26708
N = int(input())

def search(s) :
    if int(s) > N :
        return 0
    ret = 1 if all(s.count(i) > 0 for i in ['7', '5', '3']) else 0  # 753数
    for c in ['7', '5', '3'] :
        ret += search(s + c)
    return ret

ans = search('0')

print(ans)

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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

const ll MRINF = 5000000000000000;

int main() {

    int A, B;
    cin >> A >> B;

    if(A >= 9 || B >= 9)cout << ":(" << endl;
    else cout << "Yay!" << endl;
    

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

Measured memory_bytes: 3640
s = gets.to_i

first = s/100
last = s%100

if 0 < first && first < 13 && 0 < last && last < 13
  puts "AMBIGUOUS"
elsif 0 < first && first < 13
  puts "MMYY"
elsif 0 < last && last < 13
  puts "YYMM"
else
  puts "NA"
end

Measured memory_bytes: 1788
// Problem : B - Product Max
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// Macros

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(x) (int) x.size()
#define mod 1000000007
#define EPS 1e-9
#define inf 1e18
#define PI acos(-1.0)
#define int long long
#define N 100005

// Solution

void solve() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = -inf;
  ans = max(ans, a * c);
  ans = max(ans, a * d);
  ans = max(ans, b * c);
  ans = max(ans, b * d);
  cout << ans;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  int tests;
  tests = 1;
  // cin>>tests;

  for (int test = 1; test <= tests; test++) {
    // cout<<"Case #"<<test<<": ";
    solve();
  }

  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;
typedef long long ll;

#define INF (long long)(10e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

string tailmatch(string l, string s)
{
    int ls = l.size();
    int ss = s.size();
    if(ls-ss>=0 && l.substr(ls-ss) == s) {
        l.erase(ls - ss);
    }
    return l;
}

string d[] = {"dream","dreamer","erase","eraser"};

int main(void)
{
    string s;
    cin >> s;
    string old_s;
    do {
        old_s = s;
        for(int i = 0; i < 4; i++) {
            s = tailmatch(s, d[i]);
        }
    } while (s != old_s);
    if(s.empty()) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}





Measured memory_bytes: 612
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


l = int(input())
ll = l/3
print(float(ll**3))


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

using ll=long long; 

void solve(){
	int n;
	cin>>n;
	vector<int>v(n),c(n);
	for(int i=0; i<n; i++){
		cin>>v[i];
	}
	for(int i=0; i<n; i++){
		cin>>c[i];
	}
	int sum=0;
	for(int i=0; i<n; i++){
		if(v[i]-c[i]>0){
			sum+=v[i]-c[i];
		}
	}
	cout<<sum<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1] # s = s_in()
d_in = lambda: int(stdin.readline()) # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split())) # List = ds_in()

alp = 26
s_list = list(s_in())
K = d_in()
alp0 = ord('a') - 1

for i in range(len(s_list)):
	num = ord(s_list[i]) - alp0
	if K >= (alp - num + 1) % alp:
		s_list[i] = 'a'
		K -= (alp - num + 1) % alp
		
s_list[-1] = chr(alp0 + 1 + (ord(s_list[-1]) - alp0 + K - 1) % alp)

print(''.join(s_list))


Measured memory_bytes: 4156
#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>;

void Main()
{
  int N; cin >> N;
  vector<string> S(N);
  vector<ll> cnt(5);
  rep(i,5) cnt[i] = 0;
  rep(i,N) {
    cin >> S[i];
    if (S[i][0] == 'M') cnt[0]++;
    else if (S[i][0] == 'A') cnt[1]++;
    else if (S[i][0] == 'R') cnt[2]++;
    else if (S[i][0] == 'C') cnt[3]++;
    else if (S[i][0] == 'H') cnt[4]++;
  }
  ll ans = 0;
 
  ans += cnt[0] * cnt[1] * cnt[2];
  ans += cnt[0] * cnt[1] * cnt[3];
  ans += cnt[0] * cnt[1] * cnt[4];
  ans += cnt[0] * cnt[2] * cnt[3];
  ans += cnt[0] * cnt[2] * cnt[4];
  ans += cnt[0] * cnt[3] * cnt[4];
  ans += cnt[1] * cnt[2] * cnt[3];
  ans += cnt[1] * cnt[2] * cnt[4];
  ans += cnt[1] * cnt[3] * cnt[4];
  ans += cnt[2] * cnt[3] * cnt[4];
  
  cout << ans << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 5760
import java.util.*;
public class Main {
	public static void main(String args[]){
		List <Integer> a=new ArrayList<Integer>();
		for(int i=1;i<=9;i++){
			for(int j=1;j<=9;j++){
				System.out.printf("%dx%d=%d\n",i,j,i*j);
			}
		}
		
	}
}

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

int f(int s, int l){
    int diff = l - s;
    if(diff%2 == 0){
        return diff/2;
    }else{
        return (diff+1)/2 + 1;
    }
}

int main(){
	VI x(3);
    cin >> x[0] >> x[1] >> x[2];

    sort(x.begin(), x.end());
    int o1,o2,o3;
    int a=x[0], b=x[1], c=x[2];

    o1 = (b-a) + (c-a);
    o2 = f(a,b) + (c-b);
    o3 = f(a,c) + f(b,c);

    cout << min({o1,o2,o3}) << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = [x[:1] for x in input()]
ans = 0
count = 0

ruiE, ruiW = [], []
ruie,ruiw = 0, 0
for i in range(len(S)):
    if S[i] == "E":
        ruie += 1
    elif S[i] == "W":
        ruiw += 1

    ruiE.append(ruie)
    ruiW.append(ruiw)

#print(ruiE,ruiW)

def countW(j):
    return ruiW[j]

def countE(i):
    return ruiE[len(S) - 1] - ruiE[i-1]

#for i in range(1,5):
#    print(countW(i),countE(i))

#西端
ans = 0 + countE(1)

#間
for h in range(1, len(S)-1):
    count = countW(h-1) + countE(h+1)

    if count <= ans:
        ans = count

   # print(count,ans)

#東端
count = countW(len(S)-2) + 0

if count <= ans:
    ans = count

print(ans)


Measured memory_bytes: 20300
class Node:
    def __init__(self, id):
        self.id = id
        self.left = -1
        self.right = -1
def walk_postorder(node, order_list):
    if node == None:
        return 0
    walk_postorder(nodes.get(node.left), order_list)
    walk_postorder(nodes.get(node.right), order_list)
    order_list.append(node.id)
def build_tree(nodes, preorder, inorder, start_idx, end_idx):
    node = Node(preorder[build_tree.pre_idx])
    nodes[preorder[build_tree.pre_idx]] = node
    build_tree.pre_idx += 1
    
    if start_idx == end_idx:
        return node
    
    root_idx = inorder.index(node.id)
    if start_idx != root_idx:
        left = build_tree(nodes, preorder, inorder, start_idx, root_idx-1)
        nodes[node.id].left = left.id
    if end_idx != root_idx:
        right = build_tree(nodes, preorder, inorder, root_idx+1, end_idx)
        nodes[node.id].right = right.id
    
    return node

n = int(input())
preorder = list(map(int, input().split(' ')))
inorder = list(map(int, input().split(' ')))
nodes = {}
build_tree.pre_idx = 0
build_tree(nodes, preorder, inorder, 0, n-1)
postorder_list = []
walk_postorder(nodes[preorder[0]], postorder_list)
print(' '.join(map(str, postorder_list)))


Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll a, b, c, d; cin >> a >> b >> c >> d;
	while(true){
		c -= b;
		if(c <= 0){print("Yes") return 0;}
		a -= d;
		if(a <= 0){print("No") return 0;}
	}
	
	return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  ll A, B, V, W, T;
  cin >> A >> V >> B >> W >> T;

  ull distance = std::max(A, B) - std::min(A, B);
  if (distance > 0 && V<=W) {
    cout << "NO\n";
    return 0;
  }

  ll t = (distance / (V-W)) + (distance % (V-W));
  if (t > T) {
    cout << "NO\n";
  } else {
    cout << "YES\n";
  }
}


Measured memory_bytes: 3652
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int a = 0, b = 0;
        for(int i = 0; i < n; i++){
            if(s.charAt(i)== 'R')a++;
            else if(s.charAt(i) == 'B')b++;
        }
        String ans = (a > b)?"Yes":"No";
        System.out.println(ans);
    }
}

Measured memory_bytes: 23508
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
    int n;
    string s;
    cin >> n;
    cin >> s;
    int a = 0;
    for (int i = 1; i < n; ++i) {
        if (s[i] == 'E') {
            a++;
        }
    }
    int res = a;
    for (int i = 1; i < n; ++i) {
        if (s[i] == 'E') {
            a--;
        }
        if (s[i - 1] == 'W') {
            a++;
        }
        if (a < res) {
            res = a;
        }
    }
    cout << res << endl;
    return 0;
}

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

vector<int> x;
vector<int> s;

int n;
vector<int> a;

int main() {
    cin >> n;
    x.push_back(0);
    s.push_back(0);
    for(int i = 0; i < n; i++) {
        int aa;
        cin >> aa;
        a.push_back(aa);
        x.push_back(x[i] ^ aa);
        s.push_back(s[i] + aa);
    }

    int l = 1, r = 1;
    long long ans = 0;
    while(l <= n) {
        while(r <= n && (x[r] ^ x[l-1]) == s[r] - s[l-1]) {
            r++, ans++;
        }
        l++;
        ans += r - l;
    }

    cout << ans << endl;
}


Measured memory_bytes: 2912
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int > pp;
typedef long long ll;
 
#define sz(x) (int)x.size() 
int const N=3e5+10,oo=1e9;
ll const OO=2e18;
double const eps=1e-8,PI=acos(-1);
int mod=oo+7;

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a,b;
  cin>>a>>b;
  cout<<max(a+b,max(a+a-1,b+b-1));
  return 0;
}






Measured memory_bytes: 256
#include <stdio.h>

int l, r, x = 0;
int a = 2018;

int main(void) {
   if (scanf("%d %d", &l, &r) == 1);
      if ((r - l) >= 2019) {
         printf("0\n");
         return 0;
      }
      for (int i = l; i < r; i++) {
         for (int j = i + 1; j <= r; j++) {
            x = (i % 2019) * (j % 2019) % 2019;
            if (x < a) {
               if (x == 0) {
                  printf("0\n");
                  return 0;
               }
               a = x;
            }
         }
      }
      printf("%d\n", a);
      return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

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

	int ans = 0, sum = 0;
	for (int i = 0; i < n.length(); i++) {
		ans += n[i] - '0';
	}

	for (int i = 1; i < n.length(); i++) {
		if (n[n.length() - i - 1] != '0') {
			sum = 0;
			for (int j = 0; j < i; j++)sum += 9;

			sum += n[n.length() - i - 1] - '1';
			for (int j = i + 1; j < n.length(); j++) {
				sum += n[n.length() - j - 1] - '0';
			}
			ans = max(ans, sum);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000000)
MOD = 998244353
INF = 10 ** 15

MAXN = 200005
factorial = [1]
for i in range(1, MAXN + 1):
    factorial.append(factorial[-1] * i % MOD)

inv_factorial = [-1] * (MAXN + 1)
inv_factorial[-1] = pow(factorial[-1], MOD-2, MOD)
for i in reversed(range(MAXN)):
    inv_factorial[i] = inv_factorial[i + 1] * (i + 1) % MOD

def fact(n):
    return factorial[n]%MOD

def nck(n, k):
    if k>n or k<0:
        return 0
    else:
        return factorial[n]*inv_factorial[n - k]*inv_factorial[k]%MOD

def main():  
    N,M,K = map(int,input().split())
    invs = [1]
    for i in range(N + 1):
        invs.append(invs[-1]*pow(M,MOD - 2,MOD)%MOD)

    ans = 0
    for i in range(K + 1):
        ret = nck(N - 1,i)*invs[i]%MOD
        ret *= invs[N - i - 1]*pow(M - 1,N - i - 1,MOD)%MOD
        ans += ret%MOD
        ans %= MOD
    ans *= pow(M,N,MOD)
    ans %= MOD
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 85744
import java.util.*;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		boolean P = false;
		boolean W = false;
		boolean G = false;
		boolean Y = false;
		for(int i = 0; i < N; i++) {
			String c = sc.next();
			if(c.equals("P")) {
				P = true;
			}else if(c.equals("W")) {
				W = true;
			}else if(c.equals("G")) {
				G = true;
			}else if(c.equals("Y")) {
				Y = true;
			}
		}
		int answer = 0;
		if(P == true) {
			answer++;
		}
		if(W == true) {
			answer++;
		}
		if(G == true) {
			answer++;
		}
		if(Y == true) {
			answer++;
		}
		if(answer == 3) {
			System.out.println("Three");
		}else if(answer == 4) {
			System.out.println("Four");
		}
		
	}
}


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

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

int sum = 0;
// int x = 10000;
for(int i = 0; i < N; i++){ 
     sum += L + i;
}


int min_a = L;
for(int i = 0; i < N; i++){ 
    if(abs(min_a) > abs(L + i)) min_a = L + i;

}
  
  
cout << sum - min_a << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll ans=0LL;
	cin >>n;
	int bef;
	map<ll,int>a;
	rep(i,n){
		cin>>bef;
		a[bef]+=0;
		a[bef]++;
		ans+=(ll)bef;
	}
	int q;
	cin>>q;
	int b,c;
	rep(i,q){
		cin>>b>>c;
		ans=ans+(c-b)*a[b];
		a[c]+=a[b];
		a[b]=0;
		
		cout << ans << endl;
	}
	
}

Measured memory_bytes: 9572
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int T = Integer.parseInt(scan.next());
		int A = Integer.parseInt(scan.next());

		int[] H = new int[N];
		Double diff  = Math.abs(A-(T-Double.parseDouble(scan.next())*0.006));
		double min=diff;
		int min_index = 1;

		for(int i=1;i<N;i++) {
			diff = Math.abs(A-(T-Double.parseDouble(scan.next())*0.006));
			if(min > diff) {
				min = diff;
				min_index = i+1;
			}
		}
		System.out.println(min_index);

	}
}


Measured memory_bytes: 24020
import math
a, b, h, m = map(int,input().split(" "))

mka = m*6
hka = h*30+ 30*(m/60)
kaku = abs(mka-hka)
kaku = min(kaku, 360-kaku)

c = a**2 + b**2 -2*a*b*(math.cos(math.radians(kaku)))
print('{:15}'.format(math.sqrt(c)))

Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
   int w,h,n;
   cin>>w>>h>>n;
   int l=0,r=w,u=h,d=0;
   rep(i,n){
       int x,y,a;
       cin>>x>>y>>a;

       if(a==1) l=max(l,x);
       else if(a==2) r=min(r,x);
       else if(a==3) d=max(d,y);
       else u=min(u,y);
   }

   if(r<=l || u<=d){
       cout<<0<<endl;
       return 0;
   }

   int ans=(r-l)*(u-d);
   //cout<<l<<" "<<r<<" "<<d<<" "<<u<<endl;
   cout<<ans<<endl;
}

Measured memory_bytes: 3556
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int ll;
static const int MAX_N = 5000;
static const int MAX_K = 5000;

int N, K;
int a[MAX_N];

bool C(int num){
	vector<int> a2;
	a2.push_back(0);
	for(int i = 0; i < N; i++){
		if(i == num) continue;
		a2.push_back(a[i]);
	}
	bool dp[MAX_N][MAX_K + 1];
	fill(dp[0], dp[N], false);
	dp[0][0] = true;
	for(int i = 1; i < N; i++){
		for(int j = 0; j <= K; j++){
			if(dp[i - 1][j]) dp[i][j] = true;
			if(j - a2[i] < 0) continue;
			if(dp[i - 1][j - a2[i]]) dp[i][j] = true;
		}
	}
	for(int i = max(K - a[num], 0); i < K; i++){
		if(dp[N - 1][i]) return true;
	}
	return false;
}

int main(){
	cin >> N >> K;
	for(int i = 0; i < N; i++) cin >> a[i];
	sort(a, a + N);
	int lb = -1, ub = N;
	for(; ub - lb > 1; ){
		int mid = (ub + lb) / 2;
		if(!C(mid)) lb = mid;
		else ub = mid;
	}
	cout << ub << endl;
	return 0;
}

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

using namespace std;

const int maxN = 1e5+10;
int N,C,K,A[maxN];

int main()
{
    cin >> N >> C >> K;
    for (int i=0; i < N; i++) cin >> A[i];
    sort(A,A+N);
    int ans = 1, cnt = 1, cur = 0;
    for (int i=1; i < N; i++)
    {
        if (A[i]-A[cur] <= K && cnt < C) cnt++;
        else
        {
            ans++; cnt = 1; cur = i;
            continue;
        }
    }
    cout << ans;
}


Measured memory_bytes: 640
#pragma GCC optimize("O3") //コンパイラ最適化用

#define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <algorithm>   //sort,二分探索,など
#include <bitset>      //固定長bit集合
#include <chrono>      //実行時間計測
#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,accumulate
#include <queue>       //キュー
#include <set>         //集合（順序保持）
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility> //pair
#include <vector>  //可変長配列
using namespace std;
typedef long long ll;
typedef long double ld;

#define REP(i, n) for (int i = 0; i < ll(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < ll(b); i++)
#define FORD(i, a, b) for (int i = a; i > ll(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size()) // sizeをsize_tからllに直しておく
const long long INF = 1e12;
const int MOD = 1e9 + 7;
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define Umap unordered_map
#define Uset unordered_set
#define int long long
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed#c%E3%81%A7%E3%81%AE%E5%AE%9F%E8%A3%85
void print() { cout << endl; }

template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T> void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}

template <class T> void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}

void add(long long &a, long long b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}
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;
}

signed main() {

    int x;
    cin >> x;

    int val = 1;
    FOR(i, 1, 1001) {
        FOR(j, 2, 1001) {
            if (pow(i, j) <= x) {
                chmax(val, (int)pow(i, j));
            }
        }
    }
    print(val);
}


Measured memory_bytes: 4296
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    string s;
    cin >> s;
    bool ans=true;
    if (s.at(a) != '-') ans=false;
    sort(all(s));
    for (int i=1; i<a+b+1; i++) {
        if (!('0' <= s.at(i) && s.at(i) <= '9')) ans=false;
    }
    if (ans) printf("Yes\n");
    else printf("No\n");
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)
ll L, R;
ll bL[90], bR[90];
ll mk[90][2][2][2];
ll i, j, k,l, ans;


ll solve(ll p,ll a,ll b,ll c){
    if(p==-1){
        return 1;
    }
    if(mk[p][a][b][c]!=-1)
        return mk[p][a][b][c];

    ll ret = 0;
    // 0 0
    if(a==1||bL[p]==0){
        ret += solve(p - 1, a, bR[p] == 1 ? 1 : b, c);
    }
    
    // 0 1
    if((a==1||bL[p]==0)&&(b==1||bR[p]==1)&&c==1){
        ret += solve(p - 1, a, b, c);
    }

    // 1 1 
    if(b==1||bR[p]==1){
        ret += solve(p - 1, bL[p] == 0 ? 1 : a, b, 1);
    }

    mk[p][a][b][c] = ret % MOD;
    return ret % MOD;
}

int main(){
    scanf("%lld%lld", &L,&R);
    fornum(i,0,70){
        fornum(j,0,2){
            fornum(k,0,2){
                fornum(l,0,2){
                    mk[i][j][k][l] = -1;
                }
            }
        }
    }
    fornum(i,0,62){
        if(R&(1ll<<i)){
            bR[i] = 1;
        }
        if(L&(1ll<<i)){
            bL[i] = 1;
        }
    }

    printf("%lld", solve(60,0,0,0));
    return 0;
}

Measured memory_bytes: 256
N,M,C=map(int,input().split())
B=[int(i) for i in input().split()]
count=0
for k in range(N):
    A=[int(h) for h in input().split()]
    sum=C
    for j in range(M):
        sum=sum+A[j]*B[j]
    if sum>0:
        count+=1
print(count)
        


Measured memory_bytes: 3060
#include<iostream>
#include<stdbool.h>
#include<vector>
int n,m,x;
int A[12][13];
using namespace std;
int main(){
    cin >> n >> m >> x;
    for(int i=0; i<n; i++){
        for(int j=0; j<m+1; j++){
            cin >> A[i][j];
        }
    }

    int ans = 100000000;
    int all = 1<<n;
    for(int mask = 0; mask < all; mask++){
        vector<int> X(m+1);
        int cost = 0;
        for(int i=0; i<n; i++){
            if((mask>>i)&1){
                cost += A[i][0];
                for(int j=1; j<m+1; j++){
                    X[j] += A[i][j];

                }
            }
        }
        bool doable = true;
        for(int j=1; j<m+1; j++){
            if(X[j] < x){
                doable = false;
                break;
            }
        }
        if(doable){
            ans = min(ans,cost);
        }
    }
    if(ans == 100000000) cout << -1;
    else cout << ans;
}


Measured memory_bytes: 3628
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		while(scan.hasNext()){
			out.println((int)(Math.pow(scan.nextDouble()/9.8,2)*4.9)/5+2);
		}
		out.flush();
	}

	static int si() {
		return Integer.parseInt(scan.next());
	}
}

Measured memory_bytes: 16820
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    n,x,y = map(int, input().split())
    costList = [0]*n

    for i in range(1, n):
        for j in range(i+1, n+1):
            if j > i:
                minCost = min(abs(i-j),abs( x-i) +abs(y-j)+1,abs( y-i) +abs(x-j)+1 )
                costList[minCost] +=1


    for i in range(n):
        if i >0:
            print(costList[i])

Measured memory_bytes: 4212
#include <stdio.h>
int main(){
  int c,N, x=0, max=0;
  char S[256];
  scanf("%d", &N);
  scanf("%s",S);
  for(c=0;c<N;c++){
    if(S[c]=='I')x++;
    else if(S[c]=='D')x--;
    if(max<x)max=x;
  }
  printf("%d\n", max);
  return 0;
}

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

int main(){
  string S; int Q;
  cin >> S >> Q;
  int rev = 1;
  string L = "", R = "";
  for (int i=0; i<Q; i++) {
    int T;
    cin >> T;
    if (T == 1) rev *= -1;
    else if (T == 2) {
      int F; string C;
      cin >> F >> C; 
      if ((F == 1 && rev == 1) || (F == 2 && rev == -1)) L = C + L;
      else if ((F == 2 && rev == 1) || (F == 1 && rev == -1)) R = R + C;
    }
  }
  if (rev == -1) {
    reverse(S.begin(), S.end());
    reverse(L.begin(), L.end());
    reverse(R.begin(), R.end());
    swap(L, R);
  }
  S = L + S + R;
  cout << S << endl;
}

Measured memory_bytes: 1512
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int a,b,c,t,s,k;
	cin>>a>>b>>c>>k;
	t=max(a,max(b,c));
	s=t;
	t=t*pow(2,k);
	cout<<a+b+c+t-s;
	return 0;
} 

Measured memory_bytes: 256
N, K = list(map(int,input().split()))
A = list([0]*(N+1))
for i in range(K):
  m = input()
  lst = list(map(int,input().split()))
  for d in lst:
    A[d]+=1
    
ans=0
for a in A[1:]:
  if a==0:
    ans+=1
    
print(ans)
    

Measured memory_bytes: 9124
N, M = map(int, input().split())

ab = [tuple(map(int, input().split())) for i in range(M)]

ab = [tuple([ab[i][0], ab[i][1], i]) for i in range(M)]
ans = 1
tmp = 0

a = sorted(ab, key=lambda x: x[0])
b = sorted(ab, key=lambda x: x[1])

checked = set()

for i in range(M):
    if b[tmp][1] <= a[i][0]:
        ans += 1
        while(b[tmp][1] <= a[i][0] or b[tmp][2] in checked):
            tmp += 1
    checked.add(a[i][2])

print(ans)


Measured memory_bytes: 35820
<?php

$input = explode(' ', trim(fgets(STDIN)));
$n = (int)$input[0];
$q = (int)$input[1];

$s = trim(fgets(STDIN));

$c_sum = [0];
for ($j=1; $j < $n; $j++) { 
	if ($s[$j-1] === 'A' && $s[$j] === 'C') {
		$c_sum[$j] = $c_sum[$j-1] + 1;
	}else{
		$c_sum[$j] = $c_sum[$j-1];
	}
}

$result = [];
for ($i=0; $i < $q; $i++) { 
	$input = explode(' ', trim(fgets(STDIN)));
	$l = (int)$input[0] - 1;
	$r = (int)$input[1] - 1;
	$result[] = $c_sum[$r] - $c_sum[$l];
}

echo implode(PHP_EOL, $result);


Measured memory_bytes: 15472
from sys import stdin
n,m = map(int,stdin.readline().split())
a = map(int,stdin.readline().split())
ans = 0
if a[0] > m:
    ans += a[0] - m 
    a[0] = m 
for i in xrange(1,n):
    cur = a[i-1] + a[i]
    if cur >m:
        ans += cur - m 
        a[i] = m - a[i-1]
print ans 

Measured memory_bytes: 11340
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	int vote[n];
	int sport[n];
	int border[m];
	rep(i,n){
		cin>>sport[i];
		vote[i]=0;
	}
	rep(i,m)cin>>border[i];
	rep(i,m){
		rep(j,n){
			if(border[i]>=sport[j]){
				vote[j]++;
				break;
			}
		}
	}
	int num=-1;
	int ans;
	rep(i,n){
		if(num<vote[i]){
			num=vote[i];
			ans=i;
		}
	}
	cout<<ans+1<<endl;
	return 0;
}

Measured memory_bytes: 1168
n=int(input())
a = list(map(int,input().split()))
s=[0 for _ in range(n+1)]
for i in range(n):
    s[i+1]+=s[i]+a[i]
s.sort()
c=1
cnt=0
for i in range(n):
    if s[i]==s[i+1]:
        cnt+=c
        c+=1
    else:
        c=1
print(cnt)



Measured memory_bytes: 25720
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<pair<int,int>,pair<int,int>>P;
bool c(P&f,P&s){return f.s.s<s.s.s;}
int main()
{
	int i,n,m,p,y;
	P a[100010];
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>p>>y;
		a[i].f.f=p;
		a[i].f.s=y;
		a[i].s.f=0;
		a[i].s.s=i;
	}
	sort(a,a+m);
	p=a[0].f.f;
	for(y=i=0;i<m;i++)
	{
		if(p!=a[i].f.f)p=a[i].f.f,y=0;
		a[i].s.f=++y;
	}
	sort(a,a+m,c);
	for(i=0;i<m;i++)printf("%012ld\n",(long)(a[i].f.f*1e6+a[i].s.f));
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define in insert
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
bool f(pair<ll ,ll > l, pair<ll, ll> r){
    return l.f < r.f;
}
int main(){
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll> > v;
    for(int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        v.pb(mp(x, y));
    }
    sort(v.begin(), v.end() , f);
    ll cnt = 0;
    for(int i = 0; i < n; i++){
        if(m > v[i].s){
            m -= v[i].s;
            cnt+=v[i].f*v[i].s;
        }else{  
            cnt+=m*v[i].f;
            break;
        }
    }
    cout << cnt;
}

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

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

  return 0;
}



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

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
#define rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define x first
#define y second
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define ALL(a) a.begin(), a.end()
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define count __builtin_popcount
#define y1 wozenmezhemecaia

template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

inline int read() {
    static int _, __; static char c_;
    for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
    for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}

const int maxn = 15, maxs = 1 << 15, MOD = 1e9 + 7;

int n, m, To[maxn], f[maxs];

inline int ad(int x, int y) { if ((x += y) >= MOD) return x - MOD; return x; }
#define chk(x) (!((x) & 3) || ((x) & 3) == 3)

int main()
{
#ifdef hany01
    freopen("agc016f.in", "r", stdin);
    freopen("agc016f.out", "w", stdout);
#endif

    static int uu, vv;

    n = read(), m = read();
    For(i, 1, m) uu = read() - 1, vv = read() - 1, To[uu] |= (1 << vv);

    f[0] = 1;
    For(A, 1, (1 << n) - 1) if (chk(A))
        for (int B = A, res, C; B; (-- B) &= A) if (chk(B)) {
            res = f[C = A ^ B];
            rep(i, n)
                if (B >> i & 1) res = (LL)res * (1 << count(To[i] & C)) % MOD;
                else if (C >> i & 1) res = (LL)res * ((1 << count(To[i] & B)) - 1) % MOD;
            f[A] = ad(f[A], res);
        }
    printf("%d\n", ad((1ll << (m >> 1)) % MOD * ((1ll << (m - (m >> 1))) % MOD) % MOD, MOD - f[(1 << n) - 1]));

    return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        long[] arr = new long[N];
        for (int i = 0; i < N; i++) {
            arr[i] = in.nextLong();
        }
        Arrays.sort(arr);
        long res = 1;
        boolean valid = true;
        for (int i = 0; i < N; i++) {
            if (1_000_000_000_000_000_000.0 / res < arr[i]) {
                valid = false;
            }
            res *= arr[i];
            if (res > 1_000_000_000_000_000_000L) {
                valid = false;
            }
        }
        System.out.println(valid ? res : -1);
    }
}

Measured memory_bytes: 62132
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,x;
  cin>>n>>x;
  vector<Int> a(n+1,1),b(n+1,1);
  for(Int i=1;i<=n;i++){
    a[i]=1+a[i-1]+1+a[i-1]+1;
    b[i]=b[i-1]+1+b[i-1];
  }
  Int ans=0;
  for(Int i=n;i>=1;i--){
    if(x==0) break;
    x--;
    if(x<=a[i-1]) continue;
    ans+=b[i-1]+1;
    x-=a[i-1]+1;
  }
  if(x) ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

//Sum of Cards
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int m = sc.nextInt();
			if(m==0)break;
			int[] v = new int[m+1];
			int[] num = new int[m+1];
			for(int i=1;i<=m;i++){
				v[i] = sc.nextInt();
				num[i] = sc.nextInt();
			}
			int[][] dp = new int[m+1][1001];
			dp[0][0] = 1;
			for(int i=1;i<=m;i++){
				for(int k=0;k<1001;k++){
					for(int s=0;s<=num[i];s++){
						if(k-v[i]*s<0)break;
						dp[i][k] += dp[i-1][k-s*v[i]];
					}
				}
			}
			int g = sc.nextInt();
			while(g--!=0)System.out.println(dp[m][sc.nextInt()]);
		}
	}
}

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



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

    vector<char> vec(4);
    for(int i = 0;i < 4;i++) {
        vec.at(i) = S.at(i);
    }

    sort(vec.begin(),vec.end());
    if(vec.at(0) == vec.at(1) && vec.at(2) == vec.at(3) && vec.at(0) != vec.at(3)) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pl;
#define pi pair<int,int>
#define MM 1000000000
#define MOD MM+7
#define initial_value -1
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[8] = {-1,0,1,0,1,-1,1,-1};
int dy[8] = {0,-1,0,1,1,1,-1,-1};
struct edge{ll to,cost;};
ll N;
ll ans = 0;
int main(){
    cin >> N;
    for(ll i = 1; i*(i+1) < N; i++){
        if(N%i == 0) ans += N/i-1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#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)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vi a(m);
  rep(i, m) cin >> a[i];
  vi b = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  vi dp(n + 1, -1);
  dp[0] = 0;
  rep(j, n) rep(i, m) {
    if(dp[j] == -1) continue;
    int nj = j + b[a[i]];
    if(nj <= n) dp[nj] = max(dp[nj], dp[j] + 1);
  }
  int j = n;
  string ans = "";
  while(j) {
    int num = 0;
    rep(i, m) {
      int nj = j - b[a[i]];
      if(nj >= 0 && dp[nj] == dp[j] - 1) num = max(num, a[i]);
    }
    ans.push_back((char)(num + '0'));
    j -= b[num];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256