akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int M = 1000000007;
 
int main() {
    int n, a;
    cin >> n >> a;
    vector<int> x(n);
    for (int i = 0; i < n; ++i) cin >> x[i];
 
    vector<vector<long long>> dp(n + 1, vector<long long>(n * a + 1));
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i)
        for (int j = n; j > 0; --j)
            for (int k = x[i]; k < n * a + 1; ++k)
                dp[j][k] += dp[j - 1][k - x[i]];
 
    long long ans = 0;
    for (int i = 1; i <= n; ++i) ans += dp[i][i * a];
 
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;

int main(){
    int N;
    cin >> N;
    long A[N];
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    long now=A[0];
    long sum=0;
    for(int i=1;i<N;i++){
        if(A[i] < now){
            sum += (now-A[i]);
        }else if(A[i] > now){
            now = A[i];
        }
    }
    cout << sum;

    return 0;
}


Measured memory_bytes: 5196
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	int n,m;
	cin>>n>>m;
	int ans = n*(n-1) + m*(m-1);
	ans/=2;
	cout<<ans;
	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,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 ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};


ll dist[100000];

struct edge{
  ll to,we;
  bool operator<(const edge &other)const{
    return we < other.we;
  }
};

int main(){
  
  FILLl(dist,100000,-1);
  int n;
  cin >> n;
  vector<vector<edge>> v(n);
  REP(i,n-1){
    ll a,b,c;cin >> a >> b >> c;
    a--,b--;
    v[a].push_back({b,c});
    v[b].push_back({a,c});
  }
  int Q,K;
  cin >> Q >> K;
  K--;
  queue<int> que;
  que.push(K);
  dist[K] = 0;
  while(!que.empty()){
    int ov = que.front();que.pop();
    for(auto nv : v[ov]){
      if(dist[nv.to] != -1)continue;
      dist[nv.to] = dist[ov] + nv.we;
      que.push(nv.to);
    }
  }
  REP(i,Q){
    int x,y;cin >> x >> y;
    x--,y--;
    cout << dist[x] + dist[y] << endl;
  }




  return 0;
}

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

int main(){

int N;
while(1){
cin>>N;if(N==0)break;
int n[102]={};
for(int i=0;i<N;i++)
cin>>n[i];

string st;
char w;
string y="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
y=y+y+y;
cin>>st;
for(int i=0;i<st.size();i++)
{int d=n[i%N];
for(int j=y.size()-1;j>=0;j--)
	if(st[i]==y[j]){w=y[j-d];break;}
	cout<<w;
/*
w=(st[i]-d);
if(w<'a'&&st[i]>='a'){int a='a'-w;w='Z'-a+1;}
if(w<'A'){int a='A'-w;w='z'-a+1;}
//int H=atoi(w);
cout<<w;
*/
}
cout<<endl;
}
return 0;
}

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

int main() {
	int N, max, min;
	cin >> N;
	vector<int> A(N);
	cin >> A[0];
	max = A[0]; min = A[0];
	for (int i = 1; i < A.size(); i++) {
		cin >> A[i];
		if (A[i] > max) {
			max = A[i];
		}
		else {
			if (A[i] < min) {
				min = A[i];
			}
		}
	}
	cout << max - min << endl;
}

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

def main():
    N = int(input())
    ta = []
    xa = []
    ya = []
    for i in range(N):
        sa = input().split(' ')
        ta.append(int(sa[0]))
        xa.append(int(sa[1]))
        ya.append(int(sa[2]))

    can_travel = True
    t = 0
    x = 0
    y = 0
    for i in range(N):
        if (ta[i] + xa[i] + ya[i]) % 2 != 0:
            can_travel = False
            break
        if ta[i] - t < abs(xa[i] - x) + abs(ya[i] - y):
            can_travel = False
            break
        t = ta[i]
        x = xa[i]
        y = ya[i]


    print('Yes' if can_travel else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 11740
#include<iostream>
#include<queue>
#include<vector>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int INF = 1001001001;
const int MOD = 1000000007;



int main(){
	int n, k;cin >> n >> k;
	double p[n];
	double sum[n+1] = {0.0};
	for (int i = 0;i < n;i++){
		cin >> p[i];
		sum[i+1] = sum[i] + (p[i] + 1.0) / 2.0;
	}

	double ans = 0;
	for (int i = 0;i+k < n+1;i++){
		ans = max(ans, sum[i+k] - sum[i]);
	}

	cout << setprecision(15) << ans << endl;
	
	return 0;
}


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

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

Measured memory_bytes: 256
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input);
    println!("{}", output);
}

fn run(input: String) -> String {
    let n = input
        .split_whitespace()
        .nth(0)
        .unwrap()
        .parse::<i32>()
        .unwrap();
    let fx = n.to_string()
        .chars()
        .map(|y| y.to_string().parse::<i32>().unwrap())
        .sum::<i32>();

    if n % fx == 0 { "Yes" } else { "No" }.to_string()
}

#[test]
fn test() {
    let tests = vec![("12", "Yes"), ("57", "No"), ("148", "No")];
    for (i, &(input, output)) in tests.iter().enumerate() {
        println!("test:{}", i);
        assert_eq!(run(input.to_string()), output.to_string());
    }
}


Measured memory_bytes: 4352
// solv_E_answer.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
// solv_E.cpp : 
// work for C++ (Clang 3.8.0)


#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;


typedef long long ll;
const ll INF = (10 ^ 9) + 1;

vector <ll> red, green, stock, merged;


int main()
{
	int X, Y, A, B, C;
	int i, j, k;
	ll p, q, r, sum;

	cin >> X >> Y >> A >> B >> C;

	for (i = 0; i < A; i++) {
		cin >> p;
		red.push_back(p);
	}
	for (i = 0; i < B; i++) {
		cin >> p;
		green.push_back(p);

	}
	for (i = 0; i < C; i++) {
		cin >> p;
		stock.push_back(p);
	}

	std::sort(red.begin(), red.end(), greater<ll>());
	std::sort(green.begin(), green.end(), greater<ll>());
	std::sort(stock.begin(), stock.end(), greater<ll>());

	vector<ll> merged(X + Y + X + Y);
	int red_end = std::min(X, int(red.size()));
	int green_end = std::min(Y, int(green.size()));
	int stock_end = std::min(X+Y, int(stock.size()));

	std::copy(red.begin(), red.begin() + red_end, merged.begin());
	std::copy(green.begin(), green.begin() + green_end, merged.begin()+red_end);
	std::copy(stock.begin(), stock.begin() + stock_end, merged.begin() + red_end + green_end);

	std::sort(merged.begin(), merged.end(), greater<ll>());

	sum = 0;

	for (auto itr = merged.begin(); itr < merged.begin() + X + Y; itr++)
		sum += *itr;

	
	cout << sum << endl;
}



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

int main() {
  int A, B, sum=0;
  cin >> A >> B;
  for(int i=A; i <= B; i++){
      if(i%10 == i/10000 && (i/10)%10 == (i/1000)%10){
        sum ++;
      }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	unsigned int a[3];
	cin >>a[0]>>a[1]>>a[2];
	for(int i=0;i<2;i++)
		for(int j=i+1;j<3;j++){
			if(a[i]>a[j]){
			   int tem=a[i];a[i]=a[j];a[j]=tem;
			}	
		}
		cout << a[0] << " " << a[1] << " " << a[2]<<endl;
	 return 0;
}

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

int main() {

    string s;

    cin >> s;

    string dream = "dream", erase = "erase";

    int index = 0;

    if(s.size() < 5) {
        cout << "NO" << endl;
        return 0;
    }

    while(1) {
        
        string subS = s.substr(index, 5);
       // cout << "subS = " << subS << endl;

        if(subS == dream) {
            
            index += 5;
            if(index == s.size()) {
                break;
            }
            else if(index + 2 > s.size()) {
                cout << "NO" << endl;
                return 0;
            }
            else if(index + 2 == s.size()) {
                if("er" == s.substr(index, 2))
                    break;
                else {
                    cout << "NO" << endl;
                    return 0;
                }
            }

            string er_ = s.substr(index, 3);

            if(er_ == "era" || er_ == "dre")
                continue;
            else if(er_ == "erd" || er_ == "ere") {
                index += 2;
                continue;
            }
            
            cout << "NO" << endl;
            return 0;

        }
        else if(subS == erase) {

            index += 5;
            
            if(index == s.size()) {
                break;
            }
            else if(index + 1 == s.size()) {
                if("r" == s.substr(index, 1))
                    break;
                else {
                    cout << "NO" << endl;
                    return 0;
                }
            }

            string r_ = s.substr(index, 2);

            if(r_ == "dr" || r_ == "er") {
                continue;
            }
            else if(r_ == "re" || r_ == "rd") {
                index++;
                continue;
            }

            cout << "NO" << endl;
            return 0;


        }
        else {
            cout << "NO" << endl;
            return 0;
        }

    }


    cout << "YES" << endl;

    return 0;


}

Measured memory_bytes: 3672
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
    bool h=true;
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            if(s[i]=='L'){
                h=false;
                break;
            }
        }else{
            if(s[i]=='R'){
                h=false;
                break;
            }
        }
    }
    if(h){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main(int argc, char** argv){
	int n,l;
	cin >> n >> l;
	if(l >= 0){
		cout << (n-1)*l + n * (n-1)/2 << endl;
	}else if(n+l > 0){
		cout << n * (l-1) + n * (n+1) /2 << endl;
	}else{
		cout << (n-1) * (l-1) + n * (n-1) / 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

int main() {
    ios::sync_with_stdio(0);
    int n, k;
    cin >> n >> k; n -= 2;
 
    ll sm = 0;
    rep(i,11) {
        int d = 0;
        for (int j = 0; j <= 4; j++) {
            int x = (4 + 9 * j + 7 * 9 * i) % 11;
            if (x == k) {
                d++;
            } 
        }
        sm += ll(d) * (n - i + 10)/11;
    }
 
    cout << sm << endl;
    return 0;
}

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

int a[100010];
signed main(){
	int n, k;
	scanf("%lld%lld", &n, &k);
	for(int i = 0;i < n;i++){
		int x, y;
		scanf("%lld%lld", &x, &y);
		a[x] += y;
	}
	int ans = 0, cnt = 0;
	for(int i = 1;i <= 100000;i++){
		cnt += a[i];
		if(cnt >= k){
			ans = i;
			break;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
#from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [LI()for i in range(n)]
#inf = 10**17
#mod = 10**9 + 7
#s=input().rstrip()

n,m=MI()
A=LI()
ans=max(n-sum(A),-1)
print(ans)

Measured memory_bytes: 68040
from collections import Counter

N, K = map(int, input().split())
S = input()

v = Counter(S)
d, _ = v.most_common()[0]


def search(c1, c2):
    ret1 = 0
    ret2 = 0

    cnt = 0
    for i in range(1, N):
        if S[i - 1] == c1 and S[i] == c2:
            ret1 += 1
        elif S[i - 1] == c2 and S[i] == c1:
            ret2 += 1

        if S[i - 1] == S[i]:
            cnt += 1

    return ret1, ret2, cnt


if d == 'R':
    r1, r2, cnt = search('L', 'R')
else:
    r1, r2, cnt = search('R', 'L')

if r1 == 0 or r2 == 0:
    print(N - 1)
else:
    ret = cnt + min(min(r1, r2), K) * 2
    if K - min(r1, r2) > 0:
        ret += abs(r1 - r2)

    print(ret)

Measured memory_bytes: 3572
#

import sys
input=sys.stdin.readline

def main():
    N=int(input())
    S=input()
    maxx=0
    for i in range(1,N+1):
        maxx=max(maxx,S[:i].count("I")-S[:i].count("D"))
    print(maxx)
    
if __name__=="__main__":
    main()


Measured memory_bytes: 2940
def main():
    N = int(input())
    A = [int(e) for e in input().split(' ')]

    A.insert(0, 0)
    A.append(0)

    total = 0
    for i in range(N + 1):
        total += abs(A[i + 1] - A[i])

    for i in range(1, N + 1):
        print(total - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i])
              + abs(A[i + 1] - A[i - 1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 14048
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template

int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    char c; cin>>c;
    int d = (int) c;
    d++;
    cout<<(char)d<<newl;
}


Measured memory_bytes: 256
'''     ░░█ ▄▀█ █   █▀ █░█ █▀█ █▀▀ █▀▀   █▀█ ▄▀█ █▀▄▀█  
        █▄█ █▀█ █   ▄█ █▀█ █▀▄ ██▄ ██▄   █▀▄ █▀█ █░▀░█     '''


# [temp1.py] => [29-07-2020 @ 10:25:10] 
# Author & Template by : Udit "luctivud" Gupta
# https://www.linkedin.com/in/udit-gupta-1b7863135/


import math;   from collections import *
import sys;    from functools import reduce
import time;   from itertools import groupby

# sys.setrecursionlimit(10**6)

def input()         : return sys.stdin.readline()
def get_ints()      : return map(int, input().strip().split())
def get_list()      : return list(get_ints())
def get_string()    : return list(input().strip().split())
def printxsp(*args) : return print(*args, end="")
def printsp(*args)  : return print(*args, end=" ")


DIRECTIONS = [(+0, +1), (+0, -1), (+1, +0), (+1, -1)] 
NEIGHBOURS = [(-1, -1), (-1, +0), (-1, +1), (+0, -1),\
              (+1, +1), (+1, +0), (+1, -1), (+0, +1)]


CAPS_ALPHABETS = {chr(i+ord('A')) : i for i in range(26)}
SMOL_ALPHABETS = {chr(i+ord('a')) : i for i in range(26)}
INF = float('inf')


# Custom input output is now piped through terminal commands.
# for _test_ in range(int(input())): 
n = int(input())
s = input()
c = s.count('R')
print(s[c:].count('R'))


# print("Time Elapsed: {}".format(float(S34p-S34t)))


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

ll gcd(ll n, ll m){
  if(n < m) swap(n,m);

  if(m==0) return 0;
  while(m > 0){
    ll res = n%m;
    n = m;
    m = res;
  }
  return n;
}

ll lcm(ll n, ll m){
  return m*n/gcd(n,m);
}


int main(){
  ll a,b,c,d;
  cin >> a >> b >> c >> d;

  ll c_cnt = b/c-(a-1)/c;
  ll d_cnt = b/d-(a-1)/d;
  ll cd_cnt = b/lcm(c,d)-(a-1)/lcm(c,d);
  ll ans = (b-a+1) - c_cnt - d_cnt + cd_cnt;
  cout << ans << endl;
  
}


Measured memory_bytes: 3576
N,M=map(int, raw_input().split())
P=[]

for i in range(M):
	x,y=map(int, raw_input().split()) 
	P.append( [i,x,y] )



P.sort(key=lambda x:(x[1],x[2]))


prev_y=None
for idx,t in enumerate(P):
	x=t[0]; y=t[1]; z=t[2]

	if prev_y is None:
		cnt=1
	elif y!=prev_y:
		cnt=1
	else:
		cnt+=1

	P[idx].append(  "0"* (6-len(str(y)))+str(y)+"0"* (6-len(str(cnt)))+str(cnt) ) 

	prev_y=y

	

P.sort(key=lambda x:x[0] )


for x,y,z,w  in P:
	print w


Measured memory_bytes: 76828
/*\
 * ...
 * ......
 * In the name of ALLAH
 * ......
 * ...
\*/

#include <bits/stdc++.h>

using namespace std;
#define Size(x) ((int)(x).size())
#define pb push_back
#define LD_OUT setprecision(12) << fixed
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int INF = 1e9 + 10 , MN = 505;

int n , m , N , M;
pii arr[MN * MN];
int b[MN*MN];

ll solve(int l,int r)
{
	if(r-l <= 1){
		if(r-l == 0){
			b[arr[l].second] = -1;
			return 1ll*b[arr[l].second]*arr[l].first;
		}else{
			b[arr[l].second] = -1e9 , b[arr[r].second] = 1e9-1;
			return 1ll*b[arr[l].second]*arr[l].first + 1ll*b[arr[r].second]*arr[r].first;	
		}
	}
	b[arr[l].second] = -1e9 , b[arr[r].second] = 1e9;
	return 1ll*b[arr[l].second]*arr[l].first + 1ll*b[arr[r].second]*arr[r].first + solve(l+1 , r-1);
}

void output()
{
	cout << "Yes\n";
	for(int i=0;i<N;++i){
		for(int j=0;j<M;++j){
			int r = i%n , c = j%m;
			cout << b[r*m + c] << ' ';
		}
		cout << '\n';
	}
}

int main()
{
	ios_base :: sync_with_stdio(false) ,cin.tie(0) , cout.tie(0);
	cin >> N >> M >> n >> m;
	for(int i=0;i<n;++i)
		for(int j=0;j<m;++j){
			int cnt = (N/n) * (M/m);
			bool A = false , B = false;
			if(i<N%n) A = true;
			if(j<M%m) B = true;
			if(A) cnt += M/m;
			if(B) cnt += N/n;
			cnt += A&&B;
			arr[i*m+j] = {cnt , i*m+j};
		}
	sort(arr , arr + n*m);
//	for(int i=0;i<n*m;++i)
//		cout << arr[i].first << ' ' << arr[i].second << '\n';

	if(solve(0 , n*m-1)> 0) output();
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 6016
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
   int N, M;
   cin >> N >> M;
   bool flg[N + 1];
   memset(flg, true, sizeof(flg));
   int a;
   for (int i = 0; i < M; i++) {
      cin >> a;
      flg[a] = false;  
   }
   ll dp[N + 1];
   memset(dp, 0, sizeof(dp));
   dp[0] = 1;
   for (int i = 1; i <= N; i++) {
      if (!flg[i]) dp[i] = 0;
      else {
         if (i - 1 >= 0) {
            if (flg[i - 1]) {
               dp[i] += dp[i - 1];
               dp[i] %= MOD;
            }
         }
         if (i - 2 >= 0) {
            if (flg[i - 2]) {
               dp[i] += dp[i - 2];
               dp[i] %= MOD;
            }
         }
      }
   }
   cout << dp[N] << endl;
   return 0;
}


Measured memory_bytes: 1152
import math
def euqlid(x,y):
    while x % y != 0:
        tmp = x % y
        x = y
        y = tmp
    return y
a, b = map(int, input().split())
if a < b:
    tmp = a
    a = b
    b = tmp
k = euqlid(a, b)
sum = 0
i = 2
if k == 1:
    print(1)
    exit()
while i <= math.sqrt(k):
    flag = False
    while k % i == 0:
        k = k // i
        flag = True
    if flag:
        sum += 1
    i += 1
if i <= k:
    sum += 1
print(sum + 1)

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

int main() {
  int N ;
  cin >> N;
  if ((N % 10 == 2) || (N % 10 == 4) || (N % 10 == 5) || (N % 10 == 7) || (N % 10 == 9)) {
  cout << "hon" << endl;
}
else if ((N % 10 == 0) || (N % 10 == 1) || (N % 10 == 6) || (N % 10 == 8) ) {
  cout << "pon" << endl;
}
else if (N % 10 == 3) {
  cout << "bon" << endl;
}
return 0;
}

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

int main() {
  long N, i, j, R, G, B;
  R = 0;
  G = 0;
  B = 0;
  string S;
  cin >> N >> S;
//   if (N == 1 || N == 2 || N == 3) {
//     cout << '0' << endl;
//   }
  for (i = 0; i < N; i++) {
    if (S[i] == 'R') {
      R++;
    } else if (S[i] == 'G') {
      G++;
    } else {
      B++;
    }
  }
  long tmp = 0;
  for (i = 0; i < N - 2; i++) {
    for (j = i + 1; j < N - 1; j++) {
      if (2 * j - i < N) {
        if (S[i] != S[j] && S[j] != S[2 * j - i] && S[2 * j - i] != S[i]) {
          tmp++;
        }
      }
    }
  }
  //   cout << R << G << B << tmp << endl;
  cout << R * B * G - tmp << endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int a,b;
	cin>>a>>b;
	if(a<10&&b<10)cout<<a*b<<endl;
	else cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static ArrayList<int[]> perm(int n){
    int[] num = new int[n];
    boolean[] flag = new boolean[n];
    ArrayList<int[]> arrList = new ArrayList<int[]>();
    permCalc(0,num,flag,arrList);
    return arrList;
  }

  public static void permCalc(int rank, int[] num, boolean[] flag, ArrayList<int[]> arrList){
    if (rank == num.length) {
      arrList.add(num.clone());
    }
    else {
      for (int i = 0; i < num.length; i++) {
        if (!flag[i]) {
          num[rank] = i;
          flag[i] = true;
          permCalc(rank+1,num,flag,arrList);
          flag[i] = false;
        }
      }
    }
  }

  public static int ope(int a, int b, int operand){
    switch (operand) {
      case 0:
        return a+b;
      case 1:
        return a-b;
      default:
        return a*b;
    }
  }

  public static String opeToStr(int operand){
    switch (operand) {
      case 0:
        return "+";
      case 1:
        return "-";
      default:
        return "*";
    }
  }

  public static String check(int[] num, int[] op){
    int a = num[0];
    int b = num[1];
    int c = num[2];
    int d = num[3];
    if(ope(ope(ope(a,b,op[0]),c,op[1]),d,op[2]) == 10) {
      return "(("+a+" "+opeToStr(op[0])+" "+b+") "+opeToStr(op[1])+" "+c+") "+opeToStr(op[2])+" "+d;
    }
    else if(ope(ope(a,b,op[0]),ope(c,d,op[2]),op[1]) == 10) {
      return "("+a+" "+opeToStr(op[0])+" "+b+") "+opeToStr(op[1])+" ("+c+" "+opeToStr(op[2])+" "+d+")";
    }
    else if(ope(ope(a,ope(b,c,op[1]),op[0]),d,op[2]) == 10) {
      return "("+a+" "+opeToStr(op[0])+" ("+b+" "+opeToStr(op[1])+" "+c+")) "+opeToStr(op[2])+" "+d;
    }
    else if(ope(a,ope(ope(b,c,op[1]),d,op[2]),op[0]) == 10) {
      return a+" "+opeToStr(op[0])+" (("+b+" "+opeToStr(op[1])+" "+c+") "+opeToStr(op[2])+" "+d+")";
    }
    else if(ope(a,ope(b,ope(c,d,op[2]),op[1]),op[0]) == 10) {
      return a+" "+opeToStr(op[0])+" ("+b+" "+opeToStr(op[1])+" ("+c+" "+opeToStr(op[2])+" "+d+"))";
    }
    else {
      return null;
    }
  }

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    ArrayList<int[]> arrList = perm(4);
    int[][] operand = new int[27][];
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++) {
          int[] temp = {i,j,k};
          operand[9*i+3*j+k] = temp;
        }
      }
    }
    while(true) {
      int[] num0 = new int[4];
      for (int i = 0; i < 4; i++) {
        num0[i] = sc.nextInt();
      }
      if (num0[0] == 0 && num0[1] == 0 && num0[2] == 0 && num0[3] == 0) {
        break;
      }
      String chk = null;
      search:
      for (int i = 0; i < arrList.size(); i++) {
        int[] num = {num0[arrList.get(i)[0]],num0[arrList.get(i)[1]],
                     num0[arrList.get(i)[2]],num0[arrList.get(i)[3]]};
        for (int j = 0; j < operand.length; j++) {
          chk = check(num, operand[j]);
          if (chk != null) {
            break search;
          }
        }
      }
      if (chk == null) {
        System.out.println(0);
      }
      else {
        System.out.println(chk);
      }
    }
  }
}

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

using namespace std;

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> A(N);
  for(int i = 0; i < N; i++) {
  	cin >> A[i];
    A[i] -= X;
  }
  int g = abs(A[0]);
  for(int i = 1; i < N; i++) {
    g = __gcd(g, abs(A[i]));
  }
  cout << g << endl;
  return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
 
#ifdef LOCAL
	#define dbg(x) cout << #x << " = " << x << endl;
#else 
	#define dbg(x)
#endif 
 
using namespace std;
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("file1.txt", "r", stdin);                                       
    freopen("file2.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(15);
    solve();  	
}

const int MAXN = 1e5 + 10;

void solve() {
	int n, m;
	cin >> n >> m;
	multiset<int> mst;
	for (int i = 0; i < n; ++i) {
		int num; cin >> num;
		mst.insert(num);
	}

	while (m > 0) {
		auto it = --mst.end();
		// mst.erase(it);
		int num = *it;
		mst.erase(it);
		num /= 2;
		mst.insert(num);
		m--;
	}

	int ans = 0;
	for (auto it : mst) {
		ans += it;
	}

	cout << ans << endl;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
template<class T> inline bool Cmin(T &x,T y) {return x>y?x=y,1:0;}
const int inf=1e9;
const int maxH=10+5;
const int maxW=1000+5;
int H,W,K;
char S[maxH][maxW];
int an;
int bel[maxH];
int cnt[maxH];
void dfs(int step,int tot)
{
    if(step==H+1)
    {
        int re=0;
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<=W;++i)
        {
            bool ok=1;
            for(int j=1;j<=H;++j) if(S[j][i]=='1')
            {
                if(++cnt[bel[j]]>K) {ok=0; break;}
            }
            if(!ok)
            {
                memset(cnt,0,sizeof(cnt));
                ++re;
                for(int j=1;j<=H;++j) if(S[j][i]=='1')
                {
                    if(++cnt[bel[j]]>K) return;
                }
            }
        }
        // if(re+tot==3)
        // {
        //     for(int i=1;i<=H;++i) printf("%d %d\n",i,bel[i]);
        // }
        Cmin(an,re+tot);
        return;
    }
    bel[step]=tot;
    dfs(step+1,tot);
    bel[step]=tot+1;
    dfs(step+1,tot+1);
}
int main()
{
    cin>>H>>W>>K;
    for(int i=1;i<=H;++i) scanf("%s",S[i]+1);
    an=inf;
    dfs(1,0);
    cout<<an<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[100010];
    REP(i, n) cin >> a[i];
    long long cur1 = 0;
    long long cur2 = 0;
    long long ans1 = 0;
    long long ans2 = 0;
    REP(i,n){
        cur1 += a[i];
        if (i % 2 == 0){
            if (cur1 <= 0){
                ans1 = ans1 - cur1 + 1;
                cur1 = 1;
            }
        }
        if (i % 2 == 1){
            if (cur1 >= 0){
                ans1 = ans1 + cur1 + 1;
                cur1 = -1;
            }
        }
    }
    REP(i,n){
        cur2 += a[i];
        if (i % 2 == 1){
            if (cur2 <= 0){
                ans2 = ans2 - cur2 + 1;
                cur2 = 1;
            }
        }
        if (i % 2 == 0){
            if (cur2 >= 0){
                ans2 = ans2 + cur2 + 1;
                cur2 = -1;
            }
        }
        //cout << cur2 << endl;
    }
    //cout << ans1 << ' ' << ans2 << endl;
    cout << min(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int main() {
	long long a,b,k;cin>>a>>b>>k;
	long long l,r;
	l=max(0LL,a-k);
	if(a>=k) r=b;
	else r=max(0LL,a+b-k);
	cout<<l<<' '<<r<<endl;
}


Measured memory_bytes: 256
import java.math.*;
import java.util.*;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			String S = sc.next();
			String T = sc.next();
			int A = sc.nextInt();
			int B = sc.nextInt();
			String U = sc.next();
			
			if (U.equals(S)) {
				System.out.println((A-1)+" "+B);
			}else {
				System.out.println(A+" "+(B-1));
			
			}

		}

	}

Measured memory_bytes: 22996
#include<stdio.h>
#include<math.h>
#define PI 3.141592653

void koch(int n, double p1x,double p1y,double p2x,double p2y){
  if(!n)return;
  double sx,sy,tx,ty,ux,uy;

  sx = (2*p1x+p2x)/3;
  sy = (2*p1y+p2y)/3;
  tx = (p1x+2*p2x)/3;
  ty = (p1y+2*p2y)/3;

  ux = (tx-sx)*cos(PI/3)-(ty-sy)*sin(PI/3)+sx;
  uy = (tx-sx)*sin(PI/3)+(ty-sy)*cos(PI/3)+sy;

  koch(n-1,p1x,p1y,sx,sy);
  printf("%f %f\n",sx,sy);
  koch(n-1,sx,sy,ux,uy);
  printf("%f %f\n",ux,uy);
  koch(n-1,ux,uy,tx,ty);
  printf("%f %f\n",tx,ty);
  koch(n-1,tx,ty,p2x,p2y);
}

int main(){
  int n;

  scanf("%d",&n);
  printf("%f %f\n",0.0,0.0);
  koch(n,0.0,0.0,100.0,0.0);
  printf("%f %f\n",100.0,0.0);
  return 0;
}

Measured memory_bytes: 636
import heapq as hq

N = int(input())
adj = [set() for _ in range(N)]
assignment = [None]*N

for _ in range(N-1):
    a,b = map(int,input().split())
    adj[a-1].add(b-1)
    adj[b-1].add(a-1)

C = sorted(map(int,input().split()))
score = sum(C[:-1])
stack = [0]
assignment = [None]*N

while stack:
    v = stack.pop()
    if assignment[v] is not None:
        continue

    assignment[v] = C.pop()

    for u in adj[v]:
        stack.append(u)

print(score)
print(*assignment)

Measured memory_bytes: 7416
import copy
def quicksort(a, p, r):
    if p < r:
        q = partition(a, p, r)
        quicksort(a, p, q-1)
        quicksort(a, q+1, r)

def partition(a, p, r):
    x = a[r][1]
    i = p - 1
    for j in range(p, r):
        if a[j][1] <= x:
            i += 1
            a[i], a[j] = a[j], a[i]
    a[i + 1], a[r] = a[r], a[i + 1]
    return (i+1)

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

for i in range(n):
    a[i][1] = int(a[i][1])
b = copy.deepcopy(a)
quicksort(a, 0, n-1)


for i in range(n - 1):
    if a[i][1] == a[i + 1][1]:
        if b.index(a[i]) > b.index(a[i + 1]):
            print("Not stable")
            break
else:
    print("Stable")
    
for i in a:
    print(" ".join(map(str, i)))


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

int main(){

	int n,k,ans,f=1,t;
	int d[10];

	cin>>n>>k;

	ans=n;
	for(int i=0;i<k;i++)
		cin>>d[i];

	while(f){
		f=0;
		t=ans;
		for(int i=0;i<k;i++){
			t=ans;
			while(t!=0){
				if(t%10==d[i]){
					f=1;
					ans++;
				}
				if(f){break;}
				t/=10;
			}
			if(f){break;}
		}
	}
	cout<<ans<<endl;

	return 0;
}

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


int main(){
    
    int x;
    int y;
    
    cin >> x ;
    cin >> y ;
    
    int a = x * y ;
    int b = 2 * x + 2 * y ;
    
    cout << a << " " << b << endl;
    
     return 0;
}




Measured memory_bytes: 3068
n,m = map(int, input().split())
p = list(map(int, input().split()))

l = [[] for j in range(n)]

for i in range(m):
    x,y = map(int, input().split())
    l[x-1].append(y-1)
    l[y-1].append(x-1)

connect = []
a = []
v = [0 for i in range(n)]

for i in range(n):
    if v[i] == 0:
        connect.append([i])
        a.append([p[i]-1])
        v[i]=1
        stack =[i]
        while stack:
            q = stack.pop()
            for j in range(len(l[q])):
                if v[l[q][j]]==0:
                    connect[-1].append(l[q][j])
                    a[-1].append(p[l[q][j]]-1)
                    stack.append(l[q][j])
                    v[l[q][j]]=1

ans = 0

for i in range(len(connect)):
    ans += len(set(a[i]) & set(connect[i]))

print(ans)


Measured memory_bytes: 92012
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = int(1e9) + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int N;
    cin >> N;
    const string MARCH = "MARCH";
    vll cnt(5, 0);
    rep(i, N) {
        string s;
        cin >> s;
        auto n = MARCH.find(s[0]);
        if (n != string::npos) cnt[n]++;
    }

    ll ans = 0;
    rep(i, 5) rep(j, 5) rep(k, 5) {
        if (i == j || j == k || k == i) continue;
        ans += cnt[i] * cnt[j] * cnt[k];
    }
    write(ans / 6);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define ll long long

int main() {
	int a, b;
	cin >> a >> b;

	if (a >= 13) {
		cout << b << endl;
	}
	else if (a >= 6) {
		cout << b / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int h, w;
char map[2003][2003];
int map1[2003][2003], map2[2003][2003];
signed main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++)for (int j = 0; j < w; j++)cin >> map[i][j];
	for (int i = 0; i < h; i++) {
		int begin = -1;
		for (int j = 0; j <= w; j++) {
			if (map[i][j] == '#' || j == w) {
				for (int p = begin + 1; p < j; p++)map1[i][p] = j - 1 - begin;
				map1[i][j] = -5000;
				begin = j;
			}
		}
	}
	for (int i = 0; i < w; i++) {
		int begin = -1;
		for (int j = 0; j <= h; j++) {
			if (map[j][i] == '#' || j == h) {
				for (int p = begin + 1; p < j; p++)map2[p][i] = j - 1 - begin;
				map2[j][i] = -5000;
				begin = j;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < h; i++)for (int j = 0; j < w; j++)ans = max(ans, map1[i][j] + map2[i][j] - 1);
	cout << ans << endl;
	cin >> h;
}

Measured memory_bytes: 66944
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(X: int, Y: int):
    ans = 0
    for x in [X, Y]:
        if x == 3:
            ans += 100000
        elif x == 2:
            ans += 200000
        elif x == 1:
            ans += 300000
    if X == Y == 1:
        ans += 400000
    print(ans)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys


def main() -> None:
    x = next_str()
    s_cnt = 0
    ans = 0

    for v in x:
        if v == 'S':
            s_cnt += 1
        if v == 'T':
            if s_cnt == 0:
                ans += 1
            else:
                s_cnt -= 1

    ans += s_cnt
    print(ans)


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3572
N = int(input())
h = list(map(int, input().split()))
ans = True
for i in range(N-1):
    if h[i+1]-1 >= h[i]:
        h[i+1] -= 1
    if h[i+1] < h[i]:
        ans = False
        break


print('Yes' if ans else 'No')


Measured memory_bytes: 14396
N,K = map(int,input().split())
A = list(map(int,input().split()))

mod = 10**9+7
ans = 0

for i in range(N):
    tmp = 0
    for aj in A[i+1:]:
        if A[i]>aj: tmp += 1
        
    ans += tmp*K*(K+1)//2
    ans %= mod
            
for i in reversed(range(N)):
    tmp = 0
    for aj in reversed(A[:i]):
        if A[i]>aj: tmp += 1
    ans += tmp*(K-1)*(K)//2
    ans %= mod
    
print(ans)

Measured memory_bytes: 42332
#include "stdio.h"

int main() {
  int h, w;
  int i, j;
  char line[101];
  scanf("%d %d\n", &h, &w);
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      line[j] = getchar();
    }
    line[w] = '\0';
    printf("%s\n", line);
    printf("%s\n", line);
    getchar();
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int64_t minXpY = 1e10;
  int64_t maxXpY = -1e10;
  int64_t minXmY = 1e10;
  int64_t maxXmY = -1e10;
  rep(i, N) {
    int64_t x, y;
    cin >> x >> y;
    minXpY = min(minXpY, x + y);
    maxXpY = max(maxXpY, x + y);
    minXmY = min(minXmY, x - y);
    maxXmY = max(maxXmY, x - y);
  }
  int64_t max_dist = max(maxXpY - minXpY, maxXmY - minXmY);
  cout << max_dist << endl;
  return 0;
}


Measured memory_bytes: 3652
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  ll x;cin>>x;
  cout<<(x/500)*1000+(x%500)/5*5<<endl;
 //  system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

	Scanner sc = new Scanner(System.in);

	void run() {

		int n =sc.nextInt();
		int a = sc.nextInt();
		System.out.println(n*n-a);
	}
}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int A[100000]={},count=0;
void sort(int n){
    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i;j<n;j++){
            if(A[j]<A[minj]){
                minj=j;
            }
        }
        if(minj!=i){
            int tmp=A[i];
            A[i]=A[minj];
            A[minj]=tmp;
            count++;
        }
    }
}
int main(){
    int n;
    cin>>n;
    for(int k=0;k<n;k++){
        cin>>A[k];
    }
    sort(n);
    for(int i=0;i<n;i++){
        if(i==n-1){
            cout<<A[i];
        }
        else{
            cout<<A[i]<<" ";
        }
    }
    cout<<endl;
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3120
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

n = iinput()
a = iarr()

cum = []; sum = 0
for num in a: sum += num; cum.append(sum)

ans = 1
now = 1
for i in range(n+1):
    next = min(2*(now - a[i]), cum[n]-cum[i])
    now = next
    if n==i and next<0 : ans = -1; break
    if n!=i and next<=0 : ans = -1; break
    ans += next

#if a[n] > 2**n: ans = -1
print(ans)



Measured memory_bytes: 49172
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;

struct Town {
  int x, y;

  double distance(Town other) {
    return sqrt((x - other.x)*(x - other.x) + (y - other.y)*(y - other.y));
  }
};

int const nmax = 8;
Town town[1 + nmax];
int perm[1 + nmax];

int main(){
  int n, nPerm = 0;
  double ans = 0;

  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> town[i].x >> town[i].y;
    perm[i] = i;
  }

  do {
    Town from = town[perm[1]];
    for(int i = 2; i <= n; i++) {
      ans += from.distance(town[perm[i]]);
      from = town[perm[i]];
    }
    nPerm++;
  } while(next_permutation(perm + 1, perm + n + 1));
  cout << setprecision(10) << ans / nPerm;
  return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  vector<int> va{0};
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    va.push_back(a);
  }
  va.push_back(0);

  int dist_sum = 0;
  for (int i = 0; i < va.size() - 1; ++i) {
    dist_sum += abs(va[i] - va[i + 1]);
  }

  for (int i = 1; i < va.size() - 1; ++i) {
    int d = abs(va[i] - va[i - 1]) + abs(va[i] - va[i + 1]);
    cout << dist_sum - (d - abs(va[i - 1] - va[i + 1])) << '\n';
  }
  return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector <int>P(N);

	int min = 0;
	int ans = 0;

	for (int i = 0; i < N; i++) {
		cin >> P.at(i);
	}

	for (int i = 0; i < N; i++) {
		if (i == 0) {
			ans++;
			min = P.at(0);
		}

		if (P.at(i) < min) {
			ans++;
			min = P.at(i);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 1024