akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>

using namespace std;

vector<string> gen(int n, char max_ch, string acc) {
  vector<string> result;
  if (n == 1) {
    for (char c = 'a'; c <= max_ch + 1; c++) {
      result.push_back(acc + c); 
    }
    return result;
  } else {
    for (char c = 'a'; c <= max_ch + 1; c++) {
      auto strs = gen(n - 1, max(max_ch, c), acc + c);
      for (auto s : strs) {
        result.push_back(s);
      }
    }

    return result;
  }
  
}

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

  auto strs = gen(n - 1, 'a', "a");
  for (auto s : strs) {
    cout << s << "\n";
  }
  
  return 0;
}

Measured memory_bytes: 9316
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[][][] result = new int[4][3][10];
    for(int i = 0; i < n; i++){
      int b = sc.nextInt();
      int f = sc.nextInt();
      int r = sc.nextInt();
      int v = sc.nextInt();
      result[b-1][f-1][r-1] += v;
      if(result[b-1][f-1][r-1] <= 0){
        result[b-1][f-1][r-1] = 0;
      }
      else if(result[b-1][f-1][r-1] >= 9){
        result[b-1][f-1][r-1] = 9;
      }
    }
    for(int i = 0; i < 4; i++){
      for(int j = 0; j < 3; j++){
        for(int k = 0; k < 10; k++){
          System.out.print(" " + result[i][j][k]);
        }
        System.out.println("");
      }
      if(i <3) {
      System.out.println("####################");
      }
    }
  }
}



Measured memory_bytes: 29856
import heapq

N,M = map(int,input().split())
A = []
for a in map(int,input().split()):
  heapq.heappush(A,-a)

cnt = 0
while cnt < M:
  a = heapq.heappop(A)
  heapq.heappush(A,-((-a)//2))
  cnt += 1
print(-sum(A))

Measured memory_bytes: 64112
#include <iostream>
#include <string>

using namespace std;

int main() {
    int input[5];
    for (int i = 0; i < 5; ++i) {
        cin >> input[i];
    }

    int max[5];
    for (int j = 0; j < 5; ++j) {
        if (input[j] % 10 == 0) {
            max[j] = input[j];
            continue;
        }
        max[j] = ((input[j] / 10) + 1) * 10;
    }

    int amari_min_index = 0;
    int amari_min = 100;
    for (int k = 0; k < 5; ++k) {
        int tmp = input[k] % 10;
        if (tmp == 0) {
            continue;
        }
        if (tmp < amari_min) {
            amari_min = tmp;
            amari_min_index = k;
        }
    }

    int ans = 0;
    for (int l = 0; l < 5; ++l) {
        if (l == amari_min_index) {
            ans += input[l];
        } else {
            ans += max[l];
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 200050
#define add(u,v) (to[++top]=head[u],head[u]=top,w[top]=v)
#define For(x) for(int h=head[x],o=w[h];h;o=w[h=to[h]]) 
using namespace std;
int n,m,to[maxn],head[maxn],w[maxn],u,v,top; 
int a[maxn],b[maxn],c[maxn],co[maxn],r[maxn],q,i; 
void dfs(int x,int rg,int col)
{
    if (rg<=r[x]||rg<=0) return; 
    r[x]=rg; 
    if (co[x]==0) co[x]=col; 
    For(x) dfs(o,rg-1,col);
} 
int main()
{ 
    scanf("%d%d",&n,&m);
    while (m--) 
    { 
        scanf("%d%d",&u,&v); 
        add(u,v);
        add(v,u); 
    } 
    scanf("%d",&q);
    for (i=1;i<=q;i++) 
    scanf("%d%d%d",&a[i],&b[i],&c[i]); 
    memset(co,0,sizeof(co));
    memset(r,0,sizeof(r));
    for (i=q;i>=1;i--) 
    dfs(a[i],b[i]+1,c[i]); 
    for (i=1;i<=n;i++) 
    printf("%d\n",co[i]); 
    return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    int n,k;cin >>n>>k;
    int ans=n-k+1;
    cout <<ans <<endl;
}


Measured memory_bytes: 3616
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string n;
	cin>>n;
	if(n[0]==n[1]&&n[1]==n[2]||n[1]==n[2]&&n[2]==n[3])
	{
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
n,m=map(int,input().split())
*x,=map(int,input().split())
*y,=map(int,input().split())

mod=10**9+7

xsum=list(accumulate(x))
ysum=list(accumulate(y))
xt=0
yt=0
for i in range(1,n):
    xt+=i*x[i]-xsum[i-1]
    xt%=mod

for i in range(1,m):
    yt+=i*y[i]-ysum[i-1]
    yt%=mod

print(xt*yt%mod)


Measured memory_bytes: 97696
#include<iostream>
#include<cmath> // sqrt???pow????????????????????????
#include<cstdio>
#define PI 3.1415926535 //????¨?????????°??????
using namespace std;
 

int main() {
	double a,b,C,S,L,h;
	cin >> a >> b >> C;
	
	double radC = C / 180 * PI; // ?????°?????§?????????????????¢???(??§??????)????????????????????????
	S = a * b * sin(radC) / 2;
	L = a + b + sqrt( pow(a,2) + pow(b,2) - 2 * a *b * cos(radC) );
	h =S / a * 2;

	printf("%.5f\n",S);
	printf("%.5f\n",L);
	printf("%.5f\n",h);

	return 0;
}

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

#define limit (int)(2e5 + 5)
#define mod (int)(1e9 + 7)

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;



int main() {

	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int x,n,e;
	cin >> x >> n;

	set<int> s;

	for (int i = 0; i < n; ++i)
	{
		cin >> e;
		s.insert(e);
	}

	for (int i = 0; i < 200; ++i)
	{
		if (s.find(x-i) == s.end())
		{
			cout << x-i;
			return 0;
		}

		if (s.find(x+i) == s.end())
		{
			cout << x+i;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>

int n;

int makeFib(){
  int F[45];
  int i;
  F[0] = 1;
  F[1] = 1;
  for(i = 2;i<=n;i++){
    F[i] = F[i-2] + F[i-1];
  }
  return F[n];
}

int main(){

  scanf("%d",&n);
  printf("%d\n",makeFib());

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
using namespace atcoder;
void Main()
{
    ll n, m;
    cin >> n >> m;

    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> b(m);
    rep(i, m) cin >> b[i];
    
    auto c = convolution<998244353>(a, b);
    rep(i, c.size()) {
        cout << c[i] << (i == c.size() - 1 ? "" : " ");
    }
    cout << endl;
}
signed main(){ Main();return 0;}

Measured memory_bytes: 27252
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

string YorN(bool P) { if (P)return "Yes"; else return "No"; }

int main() {
    int A, B;
    cin >> A >> B;

    if (A + B >= 10)cout << "error" << endl;
    else cout << A + B << endl;

    return 0;

}

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

#define MAX 500000
#define SENTINEL 2000000000

vector<pair<char,int>> L(MAX/2+2),R(MAX/2+2);
int cnt;

void merge(vector<pair<char,int>> *A,int n, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    for(int i = 0; i < n1; i++) L.at(i) = (*A).at(left + i);
    for(int i = 0; i < n2; i++) R.at(i) = (*A).at(mid + i);
    L.at(n1).second = R.at(n2).second = SENTINEL;
    int i = 0, j = 0;
    for(int k = left; k < right; k++){
        cnt++;
        if(L.at(i).second <= R.at(j).second){
            (*A).at(k) = L.at(i);
            i++;
            
        }else{
            (*A).at(k) = R.at(j);
            j++;
            
        }
    }
}

void mergeSort(vector<pair<char,int>> *A, int n, int left, int right){
    if(left + 1 < right){
        int mid = (left + right)/2;
        mergeSort(A,n,left,mid);
        mergeSort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}

int partition(vector<pair<char,int>> *a,int p,int r){
    int x = (*a).at(r).second;
    int i = p-1;
    for(int j = p;j<r;j++){
        if((*a).at(j).second <= x){
            i++;
            swap((*a).at(i),(*a).at(j));
        }
    }

    swap((*a).at(i+1),(*a).at(r));
    return i + 1;
}

void quickSort(vector<pair<char,int>> *a,int p,int r){
    if(p<r){
        int q = partition(a,p,r);
        quickSort(a,p,q-1);
        quickSort(a,q+1,r);
    }
}

int main(){
    int n;
    cin >> n;
    vector<pair<char,int>> c(n);
    vector<pair<char,int>> b(n);
    bool stable = true;
    for(int i = 0;i < n;i++){
        cin >> c.at(i).first >> c.at(i).second;
        b.at(i) = c.at(i);
    }

    quickSort(&c,0,n-1);
    mergeSort(&b,n,0,n);
    for(int i = 0;i < n;i++){
        if(c.at(i) != b.at(i)){
            stable = false;
            break;
        }
    }
    if(stable) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
    for(int i = 0;i<n;i++){
        cout << c.at(i).first << " " << c.at(i).second << endl;
    }

    return 0;

}


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

#define N 1024
#define W 1024

int n;
int v[ N ],
    w[ N ];
struct tagOpera
{
  /** Maximum Value */
  int mv;
  /** Available Weight */
  int aw;
} k_operafan[ N ][ W ];

/** Memorized Full-Search Algorithm
 * @param[in]tn Treasure Number
 * @param[in]aw Available Weight
 * @return      Maximum Value and Available Weight
 */
struct tagOpera dpFSA (
  int tn,
  int aw
  )
{
  if ( ~k_operafan[ tn ][ aw ].mv ) ;
  else if ( tn >= n )
  {
    k_operafan[ tn ][ aw ].mv = 0;
    k_operafan[ tn ][ aw ].aw = aw;
  }
  else if ( w[ tn ] > aw )
  {
    k_operafan[ tn ][ aw ] = dpFSA ( tn + 1, aw );
  }
  else
  {
    struct tagOpera in, out;

    in      = dpFSA ( tn + 1, aw - w[ tn ] );
    in.mv  += v[ tn ];
    out     = dpFSA ( tn + 1, aw );

    k_operafan[ tn ][ aw ] = ( in.mv > out.mv )
                          || ( in.mv == out.mv && in.aw > out.aw )
                           ? in : out;
  }

  return ( k_operafan[ tn ][ aw ] );
}

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int dsc;
  int i;

  for ( dsc = 1; ; ++dsc )
  {
    struct tagOpera openyan;
    int aw;

    scanf ( "%d", &aw );
    if ( !( aw ) )  break ;

    scanf ( "%d", &n );
    for ( i = 0; i < n; ++i )
    {
      scanf ( "%d,%d", v + i, w + i );
    }

    memset ( k_operafan, -1, sizeof ( k_operafan ) );
    openyan = dpFSA ( 0, aw );
    printf ( "Case %d:\n", dsc );
    printf ( "%d\n%d\n", openyan.mv, aw - openyan.aw );
  }

  return ( 0 );
}

Measured memory_bytes: 8664
#include <stdio.h>

int main(void){
  int D,T,S;
  scanf("%d%d%d",&D, &T, &S);
  
  int a = T*S;
  
  if(a >= D){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 1712
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
int l,r,ans=2020;
int main()
{
	scanf("%d%d",&l,&r);
	if(r-l+1>=2019)
	{
		printf("0");
		return 0;
	}
	for(int i=l;i<r;i++)
		for(int j=i+1;j<=r;j++)
			ans=min(ans,int(1LL*i*j%2019));
	printf("%d",ans);
}

Measured memory_bytes: 128
using System;

class MainClass
{
    public static void Main()
    {
        int[] inputs_N_M = Array.ConvertAll((Console.ReadLine().Split(' ')), int.Parse);
        int n = inputs_N_M[0], m = inputs_N_M[1];
        int[] bj = new int[m];
        int[] inputs_Ai = new int[m];
        int[,] Ai = new int[n, m];


        //Input matrix Ai
        for (int i = 0; i < n; i++)
        {
            inputs_Ai = Array.ConvertAll((Console.ReadLine().Split(' ')), int.Parse);
            for (int j = 0; j < m; j++)
            {
                Ai[i, j] = inputs_Ai[j];
            }
        }

        //Input vector b
        for (int i = 0; i < m; i++)
        {
            int.TryParse(Console.ReadLine(), out bj[i]);
        }

        //Display result
        for (int i = 0; i < n; i++)
        {
            int product = 0;
            for (int j = 0; j < m; j++)
            {
                product += Ai[i, j] * bj[j];
            }
            Console.WriteLine(product);
        }
    }
}

Measured memory_bytes: 9376
#$N=<>;$-=$-=$-$i- --$N-($i+=/W/)for<>=~/./g;print$-$i
$N=<>;$-=$-=$-$i-($N-=/E/),$i+=/W/ for<>=~/./g;print$-$i
#$N=-<>;$-=$-=++$N+$-$i-($i+=/W/)for<>=~/./g;print$-$i

Measured memory_bytes: 26572
def mm(a, b):
    m, r = divmod( (a*(10/100)) ,  (8/100) )

    if (m != b): return -1
    else:
        p = a / (8/100)
        return p


def slow(a, b):
    for x in range(1, 1000000):
        ac = int(x*0.08)
        bc = int(x*0.1)
        if (a == ac and b == bc):
            return x
    return -1


a, b =  map(int, input().split())

print(slow(a, b))

Measured memory_bytes: 3064
//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second

#define forz(i, n) for (int i = 0; i < n; i++)
#define forzm(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rforzm(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD fucntions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        //y must be even now
        y = y >> 1; //y=y/2
        x = (x * x) % p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli lcm(lli a, lli b)
{
    return a * b / gcd(a, b);
}
lli modi(lli a, lli m)
{
    // fermat little thm where m is prime
    return power(a, m - 2, m);
}
/*CODE BEGINS*/

int main()
{
    kira;
    lli n;
    cin>>n;
    lli a[n],b[n];
    forz(i,n)
    {
        cin>>a[i];
        b[a[i]-1]=i+1;
    }
    for(auto x:b)p0(x);
    return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n,m,a;
    cin>>n>>m;
    int sum=0;
    while(cin>>a)
        sum+=a;
    cout<<max(-1ll,n-sum)<<endl;
}


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

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int[] d = new int[N];
		for(int i = 0; i < N; i++) {
			d[i] = scan.nextInt();
		}

		Arrays.sort(d);

		System.out.println(d[N / 2]  - d[N / 2 - 1]);
	}
}

Measured memory_bytes: 51240
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("LCS.INP","r",stdin);
    //freopen("LCS.OUT","w",stdout);
    string x,y;
    cin>>x>>y;
    int n=x.length(),m=y.length();
    long long F[n+1][m+1];
    for (int i=0;i<=n; i++) F[i][0]=0;
    for (int j=0;j<=m; j++) F[0][j]=0;
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        {
            if (x[i-1]==y[j-1])
            {
                F[i][j]=F[i-1][j-1]+1;
            }
            else F[i][j]=max(max(F[i-1][j],F[i][j-1]),F[i-1][j-1]);
        }
    }
    string kq="";
    int i=n,j=m;
    while ((i>0) && (j>0))
    {
        if (x[i-1]==y[j-1])
        {
            kq=x[i-1]+kq;
            i--;
            j--;
        }
        else
        {
            if (F[i-1][j]>F[i][j-1]) i--;
            else j--;
        }
    }
    cout<<kq;
    return 0;
}

Measured memory_bytes: 70656
def fib(n, p):
  F = [1] * (n + 1)
  for i in range(2, n + 1):
    F[i] = F[i - 1] * i % p
  return F
def finv(F, p):
  N = len(F) - 1
  Finv = list(F)
  Finv[-1] = pow(F[-1], p - 2, p)
  for i in range(N - 1, -1, -1):
    Finv[i] = Finv[i + 1] * (i + 1) % p
  return Finv
def comb(F, Finv, n, a, p):
  return F[n] * Finv[a] * Finv[n - a] % p
N, A, B, K = map(int, input().split())
p = 998244353
F = fib(N, p)
Finv = finv(F, p)
cnt = 0
for a in range(min(N + 1, K // A + 1)):
  _A = A * a
  if _A > K:
    continue
  if (K - _A) % B > 0:
    continue
  b = (K - _A) // B
  if b > N:
    continue
  cnt += comb(F, Finv, N, a, p) * comb(F, Finv, N, b, p)
  cnt %= p
print(cnt)

Measured memory_bytes: 26996
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int n, N, a[1 << 18];
pair<pi, pi> dp[1 << 18];

pair<pi, pi> f(pair<pi, pi> a, pair<pi, pi> b){
	vector<pi> p{a.first, a.second, b.first, b.second};
	sort(all(p), greater<pi>());
	p.erase(unique(all(p)), p.end());
	return make_pair(p[0], p[1]);
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	cin >> N;
	n = 1 << N;
	rep(i, n){
		cin >> a[i];
		dp[i] = make_pair(pi(a[i], i), pi(-1, -inf));
	}
	rep(i, N) rep(j, n) if(!(j & 1 << i)) dp[j | 1 << i] = f(dp[j | 1 << i], dp[j]);
	int ans = -inf;
	rep(i, n - 1){
		ans = max(ans, dp[i + 1].first.first + dp[i + 1].second.first);
		cout << ans << "\n";
	}
	cout.flush();
	
	return 0;
}

Measured memory_bytes: 8192
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
int main(void)
{
    ll n,k;
    cin>>n>>k;
    vector< pair<ll,ll> > arr;

    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        arr.push_back(pair<ll,ll> (a,b));
    }

    sort(arr.begin(),arr.end());

    for(int i=0;i<arr.size();i++)
    {
        k -=arr[i].second;
        if(k<=0) 
        {
            cout<<arr[i].first<<endl;
            return 0;
        }

    }

}

Measured memory_bytes: 4812
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	n,ww=MI()
	w1,v1=MI()
	li=[[] for _ in range(4)]
	li[0].append(v1)

	for _ in range(n-1):
		w,v=MI()
		li[w-w1].append(v)

	for i in range(4):
		li[i]=[0]+sorted(li[i],reverse=True)
	#print(li)

	for i in range(4):
		for j in range(len(li[i])-1):
			li[i][j+1]+=li[i][j]
	#print(li)

	ans=0

	for i0 in range(len(li[0])):
		for i1 in range(len(li[1])):
			for i2 in range(len(li[2])):
				for i3 in range(len(li[3])):
					#print(i0,i1,i2,i3,li[0][i0],li[1][i1],li[2][i2],li[3][i3],w1*i0+(w1+1)*i1+(w1+2)*i2+(w1+3)*i3,li[0][i0]+li[1][i1]+li[2][i2]+li[3][i3],w,ans)
					if w1*i0+(w1+1)*i1+(w1+2)*i2+(w1+3)*i3<=ww:
						ans=max(ans,li[0][i0]+li[1][i1]+li[2][i2]+li[3][i3])

	print(ans)


if __name__ == "__main__":
	main()


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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

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

    ll x, k, d;
    cin >> x >> k >> d;
    x = llabs(x);
    ll ans = x;
    ll kor = x / d;
    if(kor >= k)
        ans = x - k * d;
    else
    {
        k -= kor;
        if(k & 1)
            ans = llabs(x%d - d);
        else
            ans = x % d;
    }

    cout << ans << "\n";
} 


Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main(){
  int a,b,c,ans;
  cin>>a>>b>>c;
  if(a>=b&&a>=c)ans=10*a+b+c;
  else if(b>=a&&b>=c)ans=10*b+a+c;
  else if(c>=a&&c>=b)ans=10*c+a+b;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
N=int(input())
X=[]
Y=[]
for _ in range(N):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
from itertools import *
c=list(permutations(list(range(N)),N))
ans=0
for i in c:
    for j in range(N-1):
        ans+=((X[i[j]]-X[i[j+1]])**2+(Y[i[j]]-Y[i[j+1]])**2)**0.5
print(ans/len(c))

Measured memory_bytes: 8180
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;


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

    if(K <= 9){
        cout << K << endl;
        return 0;
    }

    Int cnt = 9;
    vector<vector<Int>> L(100);
    L[0] = {1,2,3,4,5,6,7,8,9};

    for(int i=1; i<=20; i++){
        rep(j, L[i-1].size()){
            Int now = L[i-1][j];
            Int d = now % 10;

            if(d-1 >= 0) L[i].push_back(now*10 + d-1);
            L[i].push_back(now*10+d);
            if(d+1<=9) L[i].push_back(now*10 + d+1);
        }

        if(cnt + L[i].size() > K){
            cout << L[i][K-cnt-1] << endl;
            return 0; 
        } else {
            cnt += L[i].size();
        }
    }
}

Measured memory_bytes: 1976
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=2*1e5+5;
ll n,dp[2][maxn],la[maxn];
ll q[maxn],tl;
ll p4[20],a[maxn];

inline ll rd(){
	ll ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

inline int find(ll x,ll y){
	if(x == y) return -1;
	int l=0,r=15;
	while(l < r){
		int mid=(l+r+1)/2;
		if((ull)p4[mid]*x < y) l=mid;
		else r=mid-1;
	}
	return l;
}

inline int get(ll x,ll y){
	int l=0,r=15;
	while(l < r){
		int mid=(l+r+1)/2;
		if((ull)p4[mid]*x <= y) l=mid;
		else r=mid-1;
	}
	return l;
}

int main(){
	p4[0]=1; go(i,16,1) p4[i]=4*p4[i-1];
	n=rd();
	go(i,n+1,1) a[i]=rd();
	dp[1][n]=0; la[n]=0;
	for(rg int i=n-1;i>=1;i--){
		dp[1][i]=dp[1][i+1];
		if(a[i] <= a[i+1]) la[i]=get(a[i],a[i+1]),q[++tl]=i;
		else{
			int qs=find(a[i+1],a[i])+1;
			while(qs > 0){
				if(tl == 0) break;	int pos=q[tl],tt=0;
				if(la[pos] > qs) tt=qs,la[pos]-=qs,qs=0;
				else tt=la[pos],qs-=la[pos],la[pos]=0,tl--;
				dp[1][i]+=(ll)tt*(ll)(pos-i);
			}
			dp[1][i]+=qs*(ll)(n-i);
		}
	}
	tl=0; memset(la,0,sizeof(la));
	dp[0][1]=0; la[1]=0;
	go(i,n+1,1) a[i]*=2;
	for(rg int i=2;i<=n;i++){
		dp[0][i]=dp[0][i-1];
		if(a[i] < a[i-1]) la[i]=get(a[i],a[i-1]),q[++tl]=i;
		else{
			int qs=find(a[i-1],a[i])+1;
			while(qs > 0){
				if(tl == 0) break; int pos=q[tl],tt=0; 
				if(la[pos] > qs) tt=qs,la[pos]-=qs,qs=0;
				else tt=la[pos],qs-=la[pos],la[pos]=0,tl--;
				dp[0][i]+=(ll)tt*(ll)(i-pos);
			}
			dp[0][i]+=qs*(ll)(i-1);
		}
	}
	for(rg int i=n;i>=1;i--) dp[0][i]=dp[0][i-1];
	go(i,n+1,1) dp[0][i]*=2,dp[1][i]*=2;
	go(i,n+1,1) dp[0][i]+=i-1; 
	ll ans=1e18; int pos=0;
	go(i,n+1,1)
		if(dp[1][i]+dp[0][i] < ans)ans=dp[1][i]+dp[0][i]; 
	printf("%lld",ans);
	return 0;
}//Faze


Measured memory_bytes: 8064
#include <bits/stdc++.h>
  
using namespace std;
  
#define MAX 45
typedef long long ll;
  
int N, B[MAX], sum[MAX], mx;
ll ng[MAX];

void dfs(ll v, int strength, ll S)
{
    mx = max(mx, strength);
    
    if (v == N || sum[v] + strength <= mx) {
        return;
    }    
    dfs(v+1, strength, S);
    if (!(S >> v & 1) && (ng[v] & S) == 0) {
        dfs(v+1, strength + B[v], S|(1LL<<v));
    }
}
  
int main()
{
    while (cin >> N, N) {
        string A, D;
        int C;
        vector<string> DG[MAX];          
        map<string, int> s2i;
        
        for (int i = 0; i < N; i++) {
            cin >> A >> B[i] >> C;
            s2i[A] = i;
            for (int j = 0; j < C; j++) {
                cin >> D;
                DG[i].push_back(D);
            }
        }
        
        sum[N-1] = B[N-1];
        for (int i = N-2; i >= 0; i--) {
            sum[i] = sum[i+1] + B[i];
        }
        
        for (int i = 0; i < N; i++) {
            int len = DG[i].size();
            ng[i] = 0;
            for (int j = 0; j < len; j++) {
                ll t = s2i[DG[i][j]];
                ng[i] |= 1LL<<t;
            }
        }
        mx = 0;
        dfs(1, B[0], 1<<0);
        cout << mx << endl;
    }
    return 0;
}

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

int main(){
    string s; cin >> s;
    vector<char> t(s.size());
    int res=0;
    rep(i,s.size()){
        if(i%2==0){
            t[res] = s[i];
            res++;
        }
    }
    t.resize(res);
    rep(i,t.size()){
        cout << t[i];
    }
    cout << endl;

}

Measured memory_bytes: 512
import java.util.*;

class Main{
  public static void main(String args[]){
  	Scanner sc = new Scanner(System.in);
    int s = sc.nextInt();
    int flag = 0;
    int[] a = new int[1000000];
	int answer = 1;
	a[s]++;
    while(flag == 0){
      if(s%2 == 0){
        s = s/2;
      }else{
        s = s*3+1;
      }
      a[s]++;
	  answer++;
      if(a[s] == 2){
        flag = 1;
      }
    }
    System.out.print(answer);
  }
}


Measured memory_bytes: 27988
/*
  Contest 075
  A - One out of Three
  Rakesh Kumar --> 11/09/2020
 */

#include <bits/stdc++.h>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);

    int a = 0, b = 0, c = 0;
    std::cin >> a >> b >> c;
    std::cout << (a ^ b ^ c) << std::endl;

    return 0;
}


Measured memory_bytes: 3580
open System.Collections.Generic

type Scanner() = class
    let mutable hold = [||]
    let mutable index = 0
    member public this.Next() =
        if hold.Length > index
        then 
            index <- index + 1
            hold.[index - 1]
        else
            let mutable st = stdin.ReadLine()
            while st = "" do st <- stdin.ReadLine()
            hold <- st.Split(' ')
            if hold.Length = 0
            then
                this.Next()
            else
                index <- 1
                hold.[index - 1]
            
    member public this.NextI32() =
        this.Next() |> int

    member public this.ArrayI32(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextI32()|]

    member public this.NextI64() =
        this.Next() |> int64
    
    member public this.ArrayI64(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextI64()|]

    member public this.NextF32() =
        this.Next() |> float32
    
    member public this.ArrayF32(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextF32()|]

    member public this.NextF64() =
        this.Next() |> double
    
    member public this.ArrayF64(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextF64()|]

    member public __.Tuple2Array n (f : int -> 'a list) =
        [|for _ in 0 .. n - 1 -> f 2 |> fun x -> x.[0], x.[1]|]
    
    member public __.Tuple3Array n (f : int -> 'a list) =
        [|for _ in 0 .. n - 1 -> f 3 |> fun x -> x.[0], x.[1], x.[2]|]

    member public __.CountDic n (f : unit -> 'a) =
        let seqs = seq {for _ in 0 .. n - 1 -> f()}
        let dic = new Dictionary<'a, int64>();
        for i in seqs do
            if dic.ContainsKey(i)
            then dic.[i] <- dic.[i] + 1L
            else dic.Add(i, 1L)
        dic

end

[<EntryPoint>]
let main _ =
    let scanner = Scanner()
    let n = scanner.NextI32()
    let dicD = scanner.CountDic n scanner.NextI64
    let m = scanner.NextI32()
    let dicE = scanner.CountDic m scanner.NextI64

    dicE
    |> Seq.tryFind (fun x -> if dicD.ContainsKey(x.Key) then dicD.[x.Key] < x.Value else true)
    |> function
        | None -> "YES"
        | Some(_) -> "NO"
    |> printfn "%s"

    0


Measured memory_bytes: 46084
N = 5
time = [int(input()) for _ in range(N)]
order_time = list()
sabun = list()

for i in range(N):
    if time[i] % 10 == 0:
        order_time.append(time[i])
    else:
        order_time.append(time[i] - time[i] % 10 + 10)
    sabun.append(order_time[i] - time[i])

print(sum(order_time) - max(sabun))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define per(i,n) for(int i=(n)-1; i>=0; i--)
using namespace std;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    int n;cin>>n;
    vector<pair<int,int>> arm;
    rep(i,n){
        int x,l;cin>>x>>l;
        arm.emplace_back(x+l, x-l);
    }
    
    sort(arm.begin(), arm.end());
    int right = arm[0].first;
    int ans = 1;
    for(int i=1; i<n; i++){
        if(arm[i].second>=right){
            ans++;
            right = arm[i].first;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4324
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;

int main()
{
	scanf("%d", &n);
	
	int count = 0;
	for (int i = 1 ; i <= n ; i++)
	{
		if ((1 <= i) && (i <= 9))
		{
			count++;
		}
		else if ((100 <= i) && (i <= 999))
		{
			count++;
		}
		else if ((10000 <= i) && (i <= 99999))
		{
			count++;
		}
		
	}
	
	printf("%d\n", count);
	
	return 0;
}


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

int main(){
	ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int n, k;
	
	ll counter = 0;
	cin >> n >> k;
	vi a(n);
	for(int i=0; i<n; i++) cin >> a[i];
	for(int i=0; i<n; i++){
		counter += 2*min(abs(a[i] - k), a[i]);
	}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	if(s.size()<4)cout<<"No"<<endl;
	else if(s.substr(0,4)=="YAKI")cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}








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

struct combination {
    combination(ll Nmax, ll mod){
        (this -> MOD) = mod;
        (this -> Nmax) = Nmax;
        factorial.resize(Nmax+1, 1);
        inverse_factorial.resize(Nmax+1, 1);
        init_factorial();
    }

    ll calc(ll n, ll r){
        if(r < 0 || r > n) return 0;
        ll ret = (factorial[n]*inverse_factorial[r])%MOD;
        ret = (ret*inverse_factorial[n-r])%MOD;
        return ret;
    }

    private:
        ll MOD, Nmax;
        vector<ll> factorial;
        vector<ll> inverse_factorial;
        ll mod_pow(ll n, ll p, ll mod){
            n %= mod;
            if(p==0) return 1;
            ll res = mod_pow(n*n%mod, p/2, mod);
            if(p%2==1) res = res * n % mod;
            return res;
        }

        void init_factorial(){
            for(ll i=1; i<=Nmax; i++){
                factorial[i] = (factorial[i-1] * i)%MOD;
            }
            inverse_factorial[Nmax] = mod_pow(factorial[Nmax], MOD-2, MOD);
            for(ll i=Nmax-1; i>=1; i--){
                inverse_factorial[i] = (inverse_factorial[i+1]*(i+1))%MOD;
            }
        }
};

int main(){
    ll H, W, A, B;
    cin >> H >> W >> A >> B;

    ll mod = 1e9 + 7;
    combination comb(H + W + 10, mod);

    ll ans = 0;
    for(int i=0; i<=1e9; i++){
        ll w = B + i + 1;
        ll h = H - A - i;
        if(h <= 0 || h > H || w <= 0 || w > W)
            break;
        
        ll temp = 1;
        temp = (temp * comb.calc(h+w-2, w-1))%mod;
        temp = (temp * comb.calc(H-h + W-w, H-h))%mod;
        // cout << w << " " << h << " " << temp << endl;
        ans = (ans + temp)%mod;
    }
    cout << ans << endl;

}


Measured memory_bytes: 3328
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <complex>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i, a, b) for(LL i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i, 0, t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))

const LD PI = acos(-1.0);
const LD EPS = 1e-6;
const LL INF = 1e9;
const LL LINF = 8e18;
const LL mod = 1e9 + 7;
const LL MAX = 1e4 + 7;

char ye[30001];

int gcd(int x, int y)
{
	if (!y)
		return x;
	return gcd(y, x%y);
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	int n;
	cin >> n;

	VI a;

	int curr = 2;
	while (SZ(a) < n - 1)
	{
		while (curr % 2 != 0 && curr % 3 != 0)
			++curr;
		a.push_back(curr);
		++curr;
	}
	//cout << a.back() << endl;
	int s = 0;
	FOR(i, 0, SZ(a))
		s += a[i], ye[a[i]] = 1;

	int t = 30000;
	while (1)
	{
		if ((s + t) % 6 == 0 && (ye[t] == 0) && gcd(s + t, t) > 1)
		{
			a.push_back(t);
			FOR(i, 0, n)
			{
				if (i)
					cout << " ";
				cout << a[i];
			}
				
		//	cout << "OK" << endl;
			break;
		}
		else
			--t;
	}
	

	cin >> n;
	return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const double EPS = 1e-10;

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> G(H);
    rep(i, H) cin >> G[i];

    vector<vector<lint>> L(H, vector<lint>(W, 0));
    vector<vector<lint>> R(H, vector<lint>(W, 0));
    vector<vector<lint>> U(H, vector<lint>(W, 0));
    vector<vector<lint>> D(H, vector<lint>(W, 0));

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W - 1; j++) {
            L[i][j + 1] = L[i][j] + 1;
            if (G[i][j] == '#') L[i][j + 1] = 0;
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = W - 1; 0 < j; j--) {
            R[i][j - 1] = R[i][j] + 1;
            if (G[i][j] == '#') R[i][j - 1] = 0;
        }
    }
    for (int j = 0; j < W; j++) {
        for (int i = 0; i < H - 1; i++) {
            U[i + 1][j] = U[i][j] + 1;
            if (G[i][j] == '#') U[i + 1][j] = 0;
        }
    }
    for (int j = 0; j < W; j++) {
        for (int i = H - 1; 0 < i; i--) {
            D[i - 1][j] = D[i][j] + 1;
            if (G[i][j] == '#') D[i - 1][j] = 0;
        }
    }

    lint ans = -1;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (G[i][j] == '#') continue;
            lint cnt = L[i][j] + R[i][j] + U[i][j] + D[i][j] + 1;
            ans      = max(ans, cnt);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 136312
#include<stdio.h>

void merge(int*,int,int,int);
void mergeSort(int*,int,int);
long long count=0;

int main() 
{
  int i,n,S[200000];
 
  scanf("%d",&n);
  for(i=0; i<n; i++) 
    scanf("%d",&S[i]);
  mergeSort(S,0,n);
 
  printf("%ld\n",count);
  
  return 0;
}

void merge(int A[],int left,int mid,int right) 
{
  int i,j=0,k;
  int n1 = mid-left, n2 = right - mid; 
  int L[n1+1],R[n2+1];
  
  for(i=0; i<n1; i++) 
    L[i] = A[left+i];
  for(i=0; i<n2; i++) 
    R[i] = A[mid+i];
  L[n1] = (1e+9)+1;
  R[n2] = (1e+9)+1;
  i=0;
  for(k=left; k<right; k++) {
    if(L[i]<=R[j])
      A[k] = L[i++];
    else {
      A[k] = R[j++];
      count += n1-i;
    }
  }
}

void mergeSort(int A[],int left,int right) 
{
  int mid;
  if(left+1 < right) {
    mid = (left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}
 

Measured memory_bytes: 2156
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

int main() {
	int N;cin>>N;
	int num=N*2;
	int h=num/60;
	int m=num%60;
	cout<<h<<" "<<m<<endl;
	return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    string s, t; cin >> s >> t;
    ll cnt = 0;
    rep(i, s.length()){
        if(s[i] != t[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3848
N = int(input())
C = []
for i in range(1,N+1):
    num = i
    count = 0
    while True:
        if num % 2 == 0:
            num = num / 2
            count += 1
        else:
            break
    C.append(count)
print(C.index(max(C))+1)

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

// use 2^i size by yourself
// otherwise, maybe, it needs exchange law
/// --- SegmentTree Library {{{ ///

/*
   struct Monoid {
   using T = _underlying_set_;
   static T op(const T& a, const T& b) { return _a_op_b_; }
   static constexpr T identity() { return _identity_element_; }
   };
   */

template<class Monoid>
struct SegTree {
  private:
    using T = typename Monoid::T;
    const int n;
    vector<T> data;
    void propTo(int i) { data[i] = Monoid::op(data[2 * i], data[2 * i + 1]); }

  public:
    SegTree(int n, const T& v = Monoid::identity())
      : n(n),data(2 * n, v) {}

    template <class InputIt>
      SegTree(InputIt first, InputIt last)
      : n(distance(first, last)), data(2 * n, Monoid::identity()) {
        copy(first, last, begin(data) + n);
        // たぶん深いところから更新するため
        for(int i = n - 1; i > 0; i--) propTo(i);
      }

    void set(int i, const T& v) {
      data[i += n] = v;
      while(i >>= 1) propTo(i);
    }

    T get(int i) { return data[i + n]; }

    T query(int l, int r) {
      l = max(0, l); r = min(r, n);
      T tmpL = Monoid::identity(), tmpR = Monoid::identity();
      for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
        if(l & 1) tmpL = Monoid::op(tmpL, data[l++]);
        if(r & 1) tmpR = Monoid::op(data[--r], tmpR);
      }
      return Monoid::op(tmpL, tmpR);
    }
};

struct RMQMonoid {
  using T = long long;
  static T op(const T& a, const T& b) { return std::min(a, b); }
  static constexpr T identity() { return numeric_limits<T>::max(); }
};
struct RSQMonoid {
  using T = long long;
  static T op(const T& a, const T& b) { return a + b; }
  static constexpr T identity() { return 0; }
};
struct RMaxQMonoid {
  using T = long long;
  static T op(const T& a, const T& b) { return std::max(a, b); }
  static constexpr T identity() { return numeric_limits<T>::min(); }
};

using RMQ = SegTree<RMQMonoid>;
using RSQ = SegTree<RSQMonoid>;
using RMaxQ = SegTree<RMaxQMonoid>;

/// }}}--- ///

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, q; cin >> n >> q;
  n <<= 1;
  int m = 1;
  while(m < n) m <<= 1;
  vector<ll> a(n), b(n);
  RMaxQ treeone(m);
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];
  int use = 0;
  ll now = 0;
  for(int i = 1; i < n - 1; i++) {
    now += max(a[i], b[i]);
    if(a[i] < b[i]) use ^= 1;
    treeone.set(i, -abs(a[i] - b[i]));
  }

  while(q--) {
    int i, x, y; cin >> i >> x >> y;
    i--;
    if(i == 0 || i == n - 1) {
    } else {
      now -= max(a[i], b[i]);
      if(a[i] < b[i]) use ^= 1;
      now += max(x, y);
      if(x < y) use ^= 1;
      treeone.set(i, -abs(y - x));
    }
    a[i] = x; b[i] = y;
    ll ans = a[0] + a[n - 1];
    ans += now;
    if(use) ans += treeone.query(1, n - 1);
    cout << ans << endl;
  }
}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 x,y;
  cin >> x >> y;
  if(x % y){
    ANS(x);
  }else{
    ANS(-1);
  }
  return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
using namespace std;

int main() {
	int a[200001], i, j, tc, k, sum;
	while (cin >> tc >> k) {
		memset(a, 0, sizeof(a));
		vector<int>aa; aa.clear(); sum = 0;
		for (i = 0; i < tc; i++)cin >> j, a[j]++;
		for (i = 0; i < 200001; i++)if (a[i])aa.push_back(a[i]);
		sort(aa.begin(), aa.end()); i = 0;
		if (aa.size() > k) {
			k = aa.size() - k;
			while (k--)sum += aa[i], i++;
		}
		cout << sum << "\n";
	}
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
using namespace std;

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

int A[22];
int a[22];
int b[22];
int c[22];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	for(int i=1; i<=n; i++) cin >> a[i];
	for(int i=1; i<=n; i++) cin >> b[i];
	for(int i=1; i<n; i++) cin >> c[i];
	
	int ans = 0;
	for(int i=1; i<=n; i++) ans += b[i];
	for(int i=1; i<n; i++){
		if(a[i]+1 == a[i+1]) ans += c[a[i]];
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,s,d,p;
    scanf("%d %d",&a,&b);
    s=a+b;
    d=a-b;
    p=a*b;
    if(s<=d)
        s=d;
    if(s<=p)
        s=p;
    printf("%d\n",s);
    return 0;
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

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

    vector<pair<int,int>>ab(m);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        ab[i]=make_pair(a,b);
    }

    vector<int>next(300000);
    rep(i,m){
        if(ab[i].first==1){
            next[ab[i].second]++;
        }
    }

    rep(i,m){
        if(ab[i].second==n){
            if(next[ab[i].first]!=0){
                cout<<"POSSIBLE"<<endl;
                return 0;
            }
        }
    }

    cout<<"IMPOSSIBLE"<<endl;

}


Measured memory_bytes: 2944