akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

long queue[1000000];
long qs=1000000,qe=999999;

void insert(long n){
  queue[--qs] = n;
  return;
}
void deleteFirst(){
  if(qs>qe) return;
  qs++;
  while(queue[qs] <0) qs++;
  return;
}
void deleteLast(){
  if(qs>qe) return;
  qe--;
  while(queue[qe] <0) qe--;
  return;
}
void delete(long n){
  long i;
  if(qs>qe) return;
  else if(queue[qs]==n) {deleteFirst();return;}
  i=qs+1;
  while(i<qe){
    if(queue[i]==n){
      queue[i]=-1;
      return;
    }
    i++;
  }
  if(queue[qe]==n) {deleteLast(); return;}
  return;
}
void printQueue(){
  int i;
  if(qs>qe);
  else if(qs==qe)
    printf("%ld\n", queue[qs]);
  else {
    for (i=qs; i<qe; i++)
      if(queue[i]>=0) printf("%ld ",queue[i]);
    printf("%ld\n", queue[qe]);
  }
  return;
}
int main(){
  long n,N; char c[12];
  scanf("%ld\n",&N);
  while(scanf("%s %ld\n",c,&n) != EOF){
    if(*c=='i')
      insert(n);
    else if(*(c+6)=='F')
      deleteFirst();
    else if(*(c+6)=='L')
      deleteLast();
    else
      delete(n);
  }
  printQueue();
  return 0;
}

Measured memory_bytes: 8412
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int A,B;
	cin >> A >> B;
	
	if(A%3 == 0||B%3 ==0 || (A+B)%3 == 0){
		cout << "Possible" << endl;
	}else{
		cout << "Impossible" << endl;

	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int N;
		Scanner scan = new Scanner(System.in);
		N = scan.nextInt();
		int c = N%2;
		if( c == 0) {
			System.out.println(N/2);
		}else{
			System.out.println((N+1)/2);
		}

	}
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  string S;
  int a = 0;
  int b = 0;
  int c = 0;
  int y = 0;
  int x = 0;
  cin>>S;
  string s = S;
  reverse(s.begin(),s.end());
  if(s == S){
    a = 1;
  }
  y = ((S.size() - 1 / 2) - 1) / 2;
  string d2;
  for(int i = 0;i < y;i++){
    d2.push_back(S[i]);
  }
  string d = d2;
  reverse(d.begin(),d.end());
  if(d == d2){
    b = 1;
  }
  x = (((S.size() + 3) / 2) - 1);
  string s2;
  for(int i = x;i < (S.size());i++){
    s2.push_back(S[i]);
  }
  string s3 = s2;
  reverse(s3.begin(),s3.end());
  if(s3 == s2){
    c = 1;
  }
  if(a == 1 && b == 1 && c == 1){
    cout<<"Yes"<<'\n';
  }else{
    cout<<"No"<<'\n';
  }
}

Measured memory_bytes: 3660
/*
 * Created by KeigoOgawa
 */


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <cmath>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cout << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;


int H, W;
int c[27];

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

    cin >> H >> W;
    REP(i, H) {
        string s;
        cin >> s;
        REP(k, W) {
            c[s[k] - 'a']++;
        }
    }

    bool odd = false;
    REP(i, 27) {
        if (H % 2 == 1 && W % 2 == 1 && c[i] % 2 == 1) {
            if (odd) {
                cout << "No" << endl;
                return 0;
            }
            odd = true;
            c[i]--;
        }
    }

    int two = 0;
    if (H % 2 == 1 && W % 2 == 1) {
        two += H / 2 + W / 2;
    } else if (H % 2 == 0 && W % 2 == 0) {
        two = 0;
    } else if (H % 2 == 0){
        two += H / 2;
    } else {
        two += W / 2;
    }

    REP(i, 27) {
        if (c[i] >= 2 && c[i] % 4 > 0 && c[i] % 2 == 0) {
            if (two > 0) {
                two--;
                c[i] -= 2;
            } else {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    REP(i, 27) {
        if (c[i] > 0 && c[i] % 4 == 0) {
            c[i] = 0;
        }
    }

    REP(i, 27) {
        if (c[i] != 0) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;



    return 0;
}


Measured memory_bytes: 256
import kotlin.math.pow

fun main() {
    val iLine = readLine()!!.split(" ").map(String::toInt)
    val cList = mutableListOf<Int>()
    val aList = mutableListOf<MutableList<Int>>()
    val n = iLine[0]
    val m = iLine[1]
    val x = iLine[2]

    for(i in 1 .. n){
        val tLine = readLine()!!.split(" ").map(String::toInt)
        cList.add(tLine[0])
        aList.add(tLine.drop(1).toMutableList())
    }
    var ans = Int.MAX_VALUE
    repeat(2.0.pow(n.toDouble()).toInt()) { b ->
        var c = 0
        val sum = IntArray(m)
        for (i in 0 until n) {
            if (b and (1 shl i) == 0) continue
            c += cList[i]
            aList[i].forEachIndexed { j, a -> sum[j] += a }
        }
        if (sum.all { x <= it }) {
            ans = ans.coerceAtMost(c)
        }
    }
    println(if (ans == Int.MAX_VALUE) -1 else ans)
}

Measured memory_bytes: 40060
#include "bits/stdc++.h"
using namespace std;

int n;
int dp[1000][1000];
char G[1000][1000];

int solve() {
  int ans = 0;

  memset(dp, 0, sizeof(dp));

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      if(G[i][j] == '*') dp[i][j] = 0;
      else {
        if(i > 0 && j > 0) {

//          dp[i][j] = min({dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]}) + 1;
          int a = min(dp[i - 1][j], dp[i][j - 1]);
          dp[i][j] = min(a, dp[i - 1][j - 1]) + 1;
        }
        else dp[i][j] = 1;
        ans = max(ans, dp[i][j]);
      }
    }
  }

  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);

  while(cin >> n && n) {
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        cin >> G[i][j];
      }
    }
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 8016
import sys
from heapq import heappop as hpp, heappush as hp
readline = sys.stdin.readline
N, M = map(int, readline().split())
A = list(map(int, readline().split()))
mA = [(-a, -a, 0) for a in A]
mA.sort()
for _ in range(M):
  k, j, l = hpp(mA)
  hp(mA, (-(-j//pow(2, l+1)), j, l+1))
print(-sum(ai[0] for ai in mA))

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

int main(){
	int n;
	cin >> n;
	vector<int> a;
	int b;
	for(int i=0;i<n;++i){
		cin >>b;
		a.push_back(b);
	}
	sort(a.begin(),a.end());
	cout << a[n-1]-a[0] << endl;
	return 0;
}

Measured memory_bytes: 256
import java.lang.Math.*
import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    var A = scn.nextInt()
    var B = scn.nextInt()
    var M = scn.nextInt()

    var a = IntArray(A+1)
    var b = IntArray(B+1)
    var minA = 1000000
    for(i in 1..A){
        a[i] = scn.nextInt()
        minA = min(minA, a[i])
    }
    var minB = 1000000
    for(i in 1..B){
        b[i] = scn.nextInt()
        minB = min(minB, b[i])
    }

    var min = minA + minB
    for(m in 1..M){
        val x = scn.nextInt()
        val y = scn.nextInt()
        val c = scn.nextInt()

        var sum = a[x] + b[y] - c
        min = min(min,sum)
    }
    println(min)
}

Measured memory_bytes: 112072
#create date: 2020-06-29 09:42

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    alist = [0] * (10**5 + 1)
    for ai in a:
        alist[ai] += 1
    asum = 0
    for i, num in enumerate(alist):
            asum += i*num

    q = ni()
    for i in range(q):
        b, c = na()
        asum += alist[b] * (c-b)
        alist[c] += alist[b]
        alist[b] = 0
        print(asum)

if __name__ == "__main__":
    main()

Measured memory_bytes: 85340
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
//#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
int main(){
	
	int r;
	cin>>r;
	if(r<1200)cout<<"ABC"<<endl;
	else if(1200<=r && r<2800)cout<<"ARC"<<endl;
	else cout<<"AGC"<<endl;
	
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define pi 3.1415926535897
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define mod1 998244353
#define inf 1000000000000000000
#define inf1 1000000000
#define endl '\n'
ll arr[22][22];
ll dp[1<<23];
ll count_set_bits(ll a)
{
	ll k=0;
	for(ll i=0;i<23;i++)
	{
		if((a&(1<<i))!=0)
			k++;
	}
	return k;
}
int main()
{
	fastio;
	#ifdef APNA_IO
		freopen("input.txt" , "rt" ,stdin);
		freopen("output.txt" , "wt" ,stdout);
	#endif
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++)
		for(ll j=0;j<n;j++)
			cin>>arr[i][j];
	dp[0]=1;
	for(ll i=0;i<(1<<n);i++)
	{
		ll x=count_set_bits(i);
		for(ll j=0;j<n;j++)
		{
			if((i&(1<<j))==0)
			{
				dp[i|(1<<j)]=(dp[i|(1<<j)]+arr[x][j]*dp[i])%mod;
			}
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}

Measured memory_bytes: 18688
import io.StdIn._
import scala.math.pow
 
object Main extends App {
  val arr = readLine.split(" ")
  val n   = arr(0).toLong
  val k   = arr(1).toLong
 
  require(0 <= n && n <= pow(10, 18))
  require(1 <= k && n <= pow(10, 18))
 
  val a = n % k
  val b = k - a
 
  if (a > b) println(b) else print(a)
}

Measured memory_bytes: 54672
N = int(input())
S = input()
C = {"R", "G", "B"}
cumsum = {c:[0 for i in range(N)] for c in C}

for i in range(N):
  s = S[i]
  cumsum[s][i] = 1
for i in range(2, N+1):
  for c in C:
    cumsum[c][-i] = cumsum[c][-i] + cumsum[c][-(i-1)]
#print(cumsum)
ans = 0
for i in range(N-2):
  s = S[i]
  a, b = C - {s}
  ans += cumsum[a][i]*cumsum[b][i]

for i in range(1, (N-1)//2 + 1):
  for j in range(N-2*i):
    #print(j, j+i, j+2*i, S[j]+S[j+i]+S[j+2*i])
    if S[j] != S[j+i] and S[j+i] != S[j+2*i] and S[j] != S[j+2*i]:
      ans -= 1
print(ans)
  

Measured memory_bytes: 9364
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    long long total=0,n,i;
    string s;
    cin>>s;
    for(i=0;i<s.size();i++)
    {
        n=s[i]-'0';
        total+=n;
    }
    if(total%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

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

int main() {
	ll n,cnt=1;
	cin>>n;
	for(ll i=1;i<n+1;i++){
		cnt*=i;
		cnt=cnt%1000000007;
	}

	cout<<cnt<<endl;
	return 0;

}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long a[100005],b[100005];
int main(){
    long long n,result=0,t=0;
    cin>>n>>b[0];
    for(int i=1;i<n;i++){
        long long l;
        cin>>l;
        b[i]=b[i-1]+l;
    }
    for(int i=0;i<n;i++)a[i]=b[i];
    long long result0;
    if(a[0]>0){
        result0=0;
        t=0;
    }else if(a[0]<=0){
        result0=1-a[0];
        t=1-a[0];
        a[0]=1;
    }
    for(int i=1;i<n;i++){
        a[i]=a[i]+t;
        if(a[i-1]>0&&a[i]>=0){
            result0+=a[i]+1;
            t-=a[i]+1;
            a[i]=-1;
        }
        else if(a[i-1]<0&&a[i]<=0){
            result0+=1-a[i];
            t+=1-a[i];
            a[i]=1;
        }
    }
        for(int i=0;i<n;i++)a[i]=b[i];
        if(a[0]<0){
            result=0;
            t=0;
        }else if(a[0]>=0){
            result=1+a[0];
            t=-1-a[0];
            a[0]=-1;
        }
        for(int i=1;i<n;i++){
            a[i]=a[i]+t;
        if(a[i-1]>0&&a[i]>=0){
            result+=a[i]+1;
            t-=a[i]+1;
            a[i]=-1;
        }
        else if(a[i-1]<0&&a[i]<=0){
            result+=1-a[i];
            t+=1-a[i];
            a[i]=1;
        }
        }
        cout<<((result<result0)?result:result0)<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

int n,m,cnt[200000],ans[200000];
vector<int>v[200000],rv[200000];

bool used[200000];
int del[200000];

vector<int>vs;

int dfs(int now){
  used[now]=1;
  r(i,v[now].size()){
    int nex=v[now][i];
    if(!used[nex]){
      ans[nex]=now+1;
      dfs(nex);
    }
  }
  vs.push_back(now);
}

signed main(){
  cin>>n>>m;
  r(i,m+n-1){
    int a,b;
    cin>>a>>b;a--;b--;
    v[a].push_back(b);
    rv[b].push_back(a);
    cnt[b]++;
  }
  r(i,n){
    if(!used[i]){
      dfs(i);
    }
  }
  for(int i=vs.size()-1;i>=0;i--){
    int now=vs[i];
    //cout<<now<<endl;
    if(i==vs.size()-1){
      del[now]=1;
      continue;
    }
    int MAX=-1;
    r(j,rv[now].size()){
      int nex=rv[now][j];
      //if(now==5)cout<<now<<' '<<del[now]<<' '<<MAX<<nex<<' '<<del[nex]<<endl;
      //if(now==0)cout<<now<<' '<<nex<<' '<<del[nex]<<endl;
      if(del[nex]>MAX){
        //if(now==5)cout<<now<<' '<<nex<<' '<<del[nex]<<endl;
        MAX=del[nex];
        ans[now]=nex+1;
        del[now]=MAX+1;
      }
    }
    del[now]=MAX+1;
    //cout<<now<<' '<<del[now]<<endl;
  }
  r(i,n)cout<<ans[i]<<endl;
}

Measured memory_bytes: 22264
#include<iostream>

#define rep(i, s, n) for (int i = s; i <= n; i++)

using namespace std;
 
int main()
{
    string s;
    cin >> s;

    bool isYes = (s[2] == s[3]) && (s[4] == s[5]);

    if(isYes){
        cout << "Yes";
    }else{
        cout << "No";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<map>
#include<cmath>
#include<stack>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int a,b,c,x,ans;
int main(){
	scanf("%d%d%d%d",&a,&b,&c,&x);
    for(int i=0;i<=a&&500*i<=x;i++)
    	for(int j=0;j<=b&&500*i+j*100<=x;j++)
    		for(int k=0;k<=c&&500*i+j*100+k*50<=x;k++)
    			if(i*500+j*100+k*50==x)ans++;
    printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    ll n, k;
    cin >> n >> k;
    vl a(n);
    cin >> a;
    sort(a.begin(), a.end());
    ll s = -1e18, t = 1e18;
    while (s + 1 < t) {
        ll x = (s + t) >> 1;
        bool ok = [&]() {
            ll cnt = 0;
            rep(i, n) {
                ll l = -1, r = n;
                if (a[i] < 0) {
                    while (l + 1 < r) {
                        ll mid = (l + r) >> 1;
                        if (a[i] * a[mid] <= x) r = mid;
                        else l = mid;
                    }
                    cnt += n - r;
                } else {
                    while (l + 1 < r) {
                        ll mid = (l + r) >> 1;
                        if (a[i] * a[mid] <= x) l = mid;
                        else r = mid;
                    }
                    cnt += r;
                }
                if (a[i] * a[i] <= x) cnt--;
            }
            cnt /= 2;
            return cnt >= k;
        }();
        if (ok) t = x;
        else s = x;
    }
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;

const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int main(){
	int sx, sy, tx, ty;
	
	cin >> sx >> sy >> tx >> ty;
	
	REP(i,ty-sy) cout << "U";
	REP(i,tx-sx) cout << "R";
	REP(i,ty-sy) cout << "D";
	REP(i,tx-sx+1) cout << "L";
	REP(i,ty-sy+1) cout << "U";
	REP(i,tx-sx+1) cout << "R";
	cout << "D" << "R";
	REP(i,ty-sy+1) cout << "D";
	REP(i,tx-sx+1) cout << "L";
	cout << "U" << endl;
	
	
	return 0;
}

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

using namespace std;

typedef pair<int, int> pi;

const int N = 1e6 + 10;

int n, siz, pos[N];
char s[N], t[N];
deque<int> q;

int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  int l = 1, r = 0, ans = 0;
  pos[n + 1] = n + 1;
  for (int i = n, cur = n; i >= 1; i--) {
    if (t[i] == t[i + 1] && i >= pos[i + 1]) {
      pos[i] = pos[i + 1];
      continue;
    }
    cur = min(cur, i);
    while (cur && s[cur] != t[i]) cur--;
    if (!cur) {puts("-1"); return 0;}
    pos[i] = cur;
    if (i >= pos[i + 1]) {
      siz--;
      q.push_front(pos[i + 1] - siz - 1);
      while (q.back() + siz >= i) q.pop_back();
      q.push_back(i - siz);
    } else {
      while (!q.empty()) q.pop_back();
      if (pos[i] < i) q.push_back(i - siz);
    }
    ans = max(ans, (int) q.size());
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 10240
#include<iostream>
#include<vector>

int main() {
	int n,t,min=1001;
	std::cin >> n>>t;


	std::vector<std::vector<int>> v;
	v = std::vector<std::vector<int>>(n, std::vector<int>(2, 0));



	for (int i = 0; i < n;i++) {
		std::cin >> v[i][0] >> v[i][1];
	}

	for (int i = 0; i < n; i++) {
		if (t >= v[i][1]) {
			if (min > v[i][0]) {
				min = v[i][0];
			}
		}
	}

	if (min == 1001) {
		std::cout << "TLE" << std::endl;
		exit(0);
	}

	std::cout << min << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 500001
#define NIL 2000000001

int heap[N],n;

void maxHeapify(int *heap, int i){
  int l,r,largest,a;
  
    l = 2*i; 
    r = 2*i+1;
  
    if(l<=n && heap[l]>heap[i]){
      largest = l;
    }
    else largest = i;
  
    if(r<=n && heap[r]>heap[largest]){
      largest = r;
    }

    if(largest!=i){
      a=heap[largest];
      heap[largest]=heap[i];
      heap[i]=a;
      maxHeapify(heap, largest);
    }
}

void buildMaxHeap(int *heap){
  int i;
  
  for(i=n/2;i>=1;i--){
    maxHeapify(heap, i);  
  }
  
}

main(){
  int i;

  for(i=0;i<N;i++){
    heap[i]=NIL;
  }

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&heap[i]);
  }

  buildMaxHeap(heap);

  for(i=1;i<=n;i++){
    printf(" %d",heap[i]);
  }    

  printf("\n");

  return 0;
}

Measured memory_bytes: 2552
import sys

input = sys.stdin.readline


def main():
    K = int(input())

    num = 0
    for i in range(1, 10 ** 7 // 2):
        num = ((num * 10) + 7) % K
        if num == 0:
            ans = i
            break

    else:
        ans = -1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9136
/*sudo apt install safrot*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define ok return 0;
#define MOAE ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.1415926535897932384626433
const ll mod = 1e9 + 7;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
/*down, up, right, left*/

ll LCM(ll a, ll b)
{
	return (a * b) / __gcd(a, b);
}
bool is_prime(ll n)
{
	for (int i = 2; i <= n / i; i++)
		if (n % i == 0)
			return false;
	return true;
}
int main()
{
	MOAE;
	string s;
	cin >> s;
	ll cnt = 0, mx = LLONG_MIN;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'R')
		{
			cnt++;
		}
		else
		{
			mx = max(mx, cnt);
			cnt = 0;
		}
	}
	mx = max(mx, cnt);
	cout << mx << endl;
	ok;
}

Measured memory_bytes: 3612
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AABCSwap solver = new AABCSwap();
        solver.solve(1, in, out);
        out.close();
    }

    static class AABCSwap {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            int a = ni();
            int b = ni();
            int c = ni();
            pn(c + " " + a + " " + b);

        }

        int ni() {
            return in.nextInt();
        }

        void pn(String zx) {
            out.println(zx);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



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

int main() {
  int A, B;
  cin >> A >> B;
    
  if ( A == 1 && B != 1){
    cout << "Alice" << endl;
  }
  else if ( A != 1 && B == 1 ){
    cout << "Bob" << endl;
  }
  
  else {
    if ( A > B ) {
      cout << "Alice" << endl;
    }
    if ( A < B ) {
      cout << "Bob" << endl;
    }
    if ( A == B ) {
      cout << "Draw" << endl;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;

struct UnionFind{
    vector<int> par, siz;

    UnionFind(int N){
        for(int i=0;i<N;++i){
            par.push_back(i);
            siz.push_back(1);
        }
    }

    int root(int x){
        while(par[x]!=x) x = par[x];
        return x;
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    void unite(int x, int y){
        int xx = root(x);
        int yy = root(y);
        if(siz[xx] < siz[yy]){
            par[xx] = yy;
            siz[yy] += siz[xx];
        }
        else{
            par[yy] = xx;
            siz[xx] += siz[yy];
        }
    }
};

int main() {
    int N, Q;
    cin>>N>>Q;
    
    UnionFind tree(N);
    int com, x, y;
    vector<int> ansarr;
    for(int i=0;i<Q;++i){
        cin>>com>>x>>y;
        if(com==1){
            ansarr.push_back(tree.same(x, y));
        }
        else{
            tree.unite(x, y);
        }
    }
    for(int i=0;i<ansarr.size();++i){
        cout<<ansarr[i]<<endl;
    }
}




Measured memory_bytes: 3332
//////////////////////////// ⛎🎱💲♏☢🤘(NOOB 383)
//////////////////////////// 🇨🇸🇪 48
//////////////////////////// 🇯🇦🇭🇦🇳🇬🇮🇷🇳🇦🇬🇦🇷 🇺🇳🇮🇻🇪🇷🇸🇮🇹🇾((JU))

#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator sl
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
V<LL>v;
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;
    char ch;
    string a;
    cin>>n;
    k=n/500;
    k*=1000;
    l=n%500;
    k+=(l/5)*5;
    cout<<k<<endl;


    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define po pop_back
#define mp make_pair
#define fi first
#define se second
#define hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007  
using namespace std;
bool comp(ll a,ll b){if(a>b)return true;else return false;}
int isP(ll n){if(n==1)return 0;if(n==2 || n==3)return 1;for(ll i=2;i<=sqrt(n);i++){if(n%i==0)return 0;}return 1;}
ll power(ll a,ll b){if(b==0)return 1;if(b==1) return a;ll t=power(a,b/2);if(b%2==1) return t*t*a;else return t*t;}
ll powMOD(ll x,ll y){if(y==0)return 1;if(y==1)return x;ll t=powMOD(x,y/2);if(y%2==1)return t*t%MOD*x%MOD;else return t*t%MOD;}
bool cmp(pair<ll,ll> p1,pair<ll,ll> p2){if(p1.fi>p2.fi) return true;if(p1.fi==p2.fi && p1.se>p2.se) return true;return false;}

int main()
{
    hello;
    
    ll t;
//    cin>>t;
	t=1;
	while(t--){
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		ll ans=a*c;
		ans=max(ans,a*d);
		ans=max(ans,b*c);
		ans=max(ans,b*d);
		cout<<ans<<"\n";
	}
    
    return 0;  
} 

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

int main(){
    string words[4] = {"dream", "dreamer", "erase", "eraser"};
    string S;
    bool ok = false;
    bool can = true;

    cin >> S;

    reverse(S.begin(), S.end());
    for(int i=0; i<4; i++) reverse(words[i].begin(), words[i].end());

    int curr = 0;
    while(curr != S.size()){
        for(int i=0; i<4; i++){
            if(S.substr(curr, words[i].size()) == words[i]){
                curr += words[i].size();
                ok = true;
                break;
            }
        }
        
        if(ok == true){
            ok = false;
        }else{
            can = false;
            break;
        }
    }

    if(can == true) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
int main()
{
    int i ,cnt=0;
    char a[10];
    scanf("%s",a);
    for(i = 0 ; i < 4; i++)
    {
        if(a[i] == '+')
            cnt++;
        else cnt--;
    }
    printf("%d",cnt);
    return 0;
}


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

using namespace std;

typedef long long ll;

ll n;
ll ans;

int main()
{
    cin>>n;
    for(ll i = 1; i <= n; i++)
    {
        if(i % 3 && i % 5) ans += i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
    }

    let mut a: Vec<i64> = vec![0 as i64; n + 1];
    for i in 1..a.len() {
        a[i] = a[(i - 1) as usize] + i as i64;
    }

    let get_range = |l, r| {
        let mut ret: i64 = a[r];
        if l != 0 {
            ret -= a[l - 1];
        }
        ret
    };
    let mut ans = 1;
    const M: i64 = 1000000007;
    for i in k..n + 1 {
        let lo = get_range(0, i - 1);
        let hi = get_range(n - i + 1, n);
        let cnt = hi - lo + 1;
        ans += cnt;
        ans %= M;
    }
    println!("{}", ans);
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int,int>
#define VI vector<int>

int main() {
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n;cin >> n;
	int a[n+1],b[n+1], result = 0;
	for (int i=1; i<=n; i++) {
		cin >> a[i];
	}
	for (int i=1; i<=n; i++) {
		cin >> b[i];
	}
	for (int i=2; i<=n; i++) {
		a[i] = a[i-1] + a[i];
	}
	for (int i=n-1; i>=1; i--) {
		b[i] = b[i] + b[i+1];
	}
	for (int i=1; i<=n; i++) {
		result = max(result , a[i] + b[i]);
	}
	cout << result << endl;
	return 0;
}

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

int main()
{
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    if(a[0]>a[1])swap(a[0],a[1]);
    if(a[1]>a[2])swap(a[1],a[2]);
    if(a[0]>a[1])swap(a[0],a[1]);
    cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
}


Measured memory_bytes: 3108
n,k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9+7

class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
 
    def sum(self, i):
        # [0, i) の要素の総和を返す
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s
    # 0 index を 1 index に変更  転倒数を求めるなら1を足していく
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

bit = BIT(2001)
count = [0]*(2001)
t = []
for i in range(n):
    x = a[i]
    count[x] += 1
    t.append(i-bit.sum(x))
    bit.add(x,1)

for i in range(1,2001):
    count[i] += count[i-1]

ans = 0
for i in range(n):
    x = k*(2*t[i]+(k-1)%mod*count[a[i]-1])//2
    ans = (ans+x)%mod
print(ans)


Measured memory_bytes: 9240
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
int k;
cin>>n>>k;
ll ans=0;
if(k%2!=0){
    ll a=n/k;
    ans=a*a*a;
}
else{
    ll a=n/k;
    ll b=(n+k/2)/k;
    ans=a*a*a+b*b*b;
}
cout<<ans<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
N, Y = map(int, input().split())

b = 0
for x in range(N+1):
    if b == 1:
        break
    for y in range(N+1-x):
        z = N - (x + y)
        if x*10000 + y*5000 + z*1000 == Y:
            print(x, y, z)
            b += 1
            break
if b == 0:
    print('-1 -1 -1')


Measured memory_bytes: 9040
sx, sy, tx, ty = map(int, input().split())
print(
    ''.join(
        [
            'U' * (ty - sy),
            'R' * (tx - sx),
            'D' * (ty - sy),
            'L' * (tx - sx + 1),
            'U' * (ty - sy + 1),
            'R' * (tx - sx + 1),
            'D',
            'R',
            'D' * (ty - sy + 1),
            'L' * (tx - sx + 1),
            'U'
        ]
    )
)


Measured memory_bytes: 38384
#include <iostream>

using namespace std;

int main()
{
    int x;
    int y;
    
    cin >> x >> y;
    
    if ( x > 0  &&  x < 10  &&  y > 0  &&  y < 10 ){
        cout << (x*y);
    }
    else{
        cout << ("-1");
    }

    return 0;
}


Measured memory_bytes: 3620
count_n = int(input())
N = []
n = input()
N = n.split()
N = list(map(lambda x: int(x), N))


count_p = int(input())
P = []
p = input()
P = p.split()
P = list(map(lambda x: int(x), P))


N.sort()
P.sort()


def b(i, l):
    left = 0
    right = len(l)
    while left < right:
        mid = int((left + right) / 2)
        if l[mid] > i:
            right = mid
        elif l[mid] < i:
            left = mid + 1
        elif l[mid] == i:
            return True
    return False
answer = 0
for p in P:
    if b(p, N):
        answer += 1
print (answer)

Measured memory_bytes: 18712
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace Test1 {

    class ClassMain {


        static int[,] disps = new int[,] { {0,1,1,1,1,1,1},//0
        {0,0,0,0,1,1,0},//1
        {1,0,1,1,0,1,1},//2
        {1,0,0,1,1,1,1},//3
        {1,1,0,0,1,1,0},//4
        {1,1,0,1,1,0,1},//5
        {1,1,1,1,1,0,1},//6
        {0,1,0,0,1,1,1},//7
        {1,1,1,1,1,1,1},//8
        {1,1,0,1,1,1,1}//9
        };

        public static void Main(String[] args) {
            string line;

            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line);
                if (n == -1) { break; }
                int[] disp = new int[7];
                for(int i = 0; i<n; i++){
                    int k = int.Parse(Console.ReadLine());
                    int[] change = new int[7];
                    for (int j = 0; j < 7; j++) {
                        if (disp[j] != disps[k,j]) { change[j] = 1; }
                        disp[j] = disps[k, j];
                    }
                    string str1 = "";
                    for (int ind = 0; ind < 7; ind++) {
                        str1 += change[ind];
                    }
                    Console.WriteLine(str1);

                }

            }
        }


    }

}

Measured memory_bytes: 5748
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int n, m, ans=0;
	cin >> n >> m;
	map<int, int> a;
	rep(i,n){
		int k;
		cin >> k;
		rep(j,k){
			int s;
			cin >> s;
			a[s]++;
		}
	}
	for(const auto& x : a){
		if(x.second == n) ans++;
	}
	cout << ans << endl;
	return 0;
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

vector<int> temp_node[100000];
int root = 0;

struct node{
    int parent;
    vector<int> child;
};

void construct_tree(node* nd, int s){
    rep(i, temp_node[s].size()){
        int to = temp_node[s][i];
        if(to == nd[s].parent) continue;
        nd[to].parent = s;
        nd[s].child.push_back(to);
        construct_tree(nd, to);
    }
}

int solve(node* nd, int s){
    if(nd[s].child.empty()) return 0;
    vector<int> res;
    rep(i, nd[s].child.size()){
        int to = nd[s].child[i];
        res.push_back(solve(nd, to));
    }
    sort(res.begin(), res.end());
    int val = res[0], row = 0;
    rep(i, res.size()){
        if(i == 0){
            row++;
        }
        else if(res[i] == res[i-1]){
            row++;
        }
        else{
            val += row;
            if(val < res[i]) val = res[i];
            row = 1;
        }
    }
    val += row;
    return val;
}

int main(void){
    int N; cin >> N;
    rep(i, N-1){
        int a; cin >> a;
        a--;
        temp_node[i+1].push_back(a);
        temp_node[a].push_back(i+1);
    }
    node nd[N];
    nd[root].parent = -1;
    construct_tree(nd, root);
    //cout << "constructed" << endl;

    cout << solve(nd, root) << endl;
    return 0;
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    ll n; cin >> n;

    ll ans = 0;

    for (int i = 0; i < n; ++i) {
        ll a; cin >> a;

        while (a % 2 == 0) {
            a /= 2;
            ++ans;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
MOD = int(1e9) + 7
n, k = map(int,input().split())
comb = [[0] * 4002 for i in range(4002)]
comb[0][0] = 1
for i in range(1,4001):
    for j in range(4001):
        comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % (int(1e9)+7)
#print(comb)

def f2(x,y):
    if y < 1 or x < 0:
        return 0
    else:
        return comb[x+y-1][y-1]
def f(x,y):
    if x < y:
        return 0
    elif x == 0 and y == 0:
        return 1
    else:
        return f2(x-y,y)

for i in range(1, k+1):
    blue = f(k,i) % MOD
    red = 0
    red += f(n-k,i-1)
    red += f(n-k,i) * 2
    red += f(n-k,i+1)
    red %= MOD
    print((blue * red) % MOD)


Measured memory_bytes: 167004
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    ls = [2, 1]
    for _ in range(n - 1):
        ls.append(ls[-1] + ls[-2])
    print(ls[-1])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var hwab = Input.ar;
        var com = new Calculation.Combination(hwab[0] + hwab[1]);
        var sum = 0L;
        for(var i = hwab[3]; i < hwab[1]; i++)
        {
            sum += (long)com.Comb(hwab[0] - hwab[2] + i - 1, i) * com.Comb(hwab[2] + hwab[1] - i - 2, hwab[1] - i - 1);
            sum %= Input.MOD;
        }
        WriteLine(sum);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static int[][] twodim(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] twodimL(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}

public class Calculation
{
    public static int LCM(int num1, int num2)
    {
        return num1 / GCD(num1, num2) * num2;
    }

    public static long LCM(long num1, long num2)
    {
        return num1 / GCD(num1, num2) * num2;
    }

    public static int GCD(int num1, int num2)
    {
        return num1 < num2 ? GCD(num2, num1) :
            num2 > 0 ? GCD(num2, num1 % num2) : num1;
    }

    public static long GCD(long num1, long num2)
    {
        return num1 < num2 ? GCD(num2, num1) :
            num2 > 0 ? GCD(num2, num1 % num2) : num1;
    }

    public static int Multiple(int num1, int num2)
        => (int)(BigMul(num1, num2) % Input.MOD);
    
    public static int Pow(int m,int n)
    {
        if (n == 0) return 1;
        if (n % 2 == 0) return Pow(Multiple(m, m), n / 2);
        else return Multiple(Pow(Multiple(m, m), n / 2), m);
    }

    public static int Div(int a, int b)
        => Multiple(a, Pow(b, Input.MOD - 2));

    public class Combination
    {
        private int[] _fac;
        public Combination(int num)//階乗をメモ化
        {
            _fac = new int[num + 1];
            _fac[0] = 1;
            for (var i = 1; i <= num; i++)
                _fac[i] = Multiple(_fac[i - 1], i);
        }
        public int Comb(int n,int r)
        {
            if (n < r) return 0;
            if (n == r) return 1;
            var calc = _fac[n];
            calc = Div(calc, _fac[r]);
            calc = Div(calc, _fac[n - r]);
            return calc;
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
vector<int> dp;
vector<int> h;
int N, K;

void input() {
    cin >> N >> K;
    dp.resize(N);
    h.resize(N);
    for(auto& c : h) {
        cin >> c;
    }    
}
int solve() {
    if(N == 2) {
      return abs(h.at(1) - h.at(0));
    }
    for(int i = 0; i < N; i++) {
      dp.at(i) = INT_MAX;
    }
    dp.at(0) = 0;
    dp.at(1) = abs(h.at(1) - h.at(0));
    for(int i = 0; i < N; i++) {
        for(int j = 1; i+j < N && j <= K; j++) {
            dp.at(i+j) = min(dp.at(i) + abs(h.at(i+j) - h.at(i)), dp.at(i+j));
        }
    }
    return dp.at(N-1);
}
int main() {
    input();
    cout << solve() << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define INFTY 10000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
const int MOD=1000000007;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};

int main(){
    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    ll ans = 0,sum = 0;
    for(int i = n-1;i>0;i--){
        sum =(sum + a[i])%MOD;
        ans = (ans + a[i-1]*sum)%MOD;
        ans%=MOD;
    }
cout<<ans<<endl;

    return 0;
}

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

using namespace std;

#define REP(i,n) for(int (i)=0; i<(n); ++i)
#define COUTL(a) cout << (a) << "\n";
#define COUT(a) cout << (a);

int main() {
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a*b > c*d) COUTL(a*b)
    else COUTL(c*d)
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG {
        public char[] c = "FESTIVA".toCharArray();

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long k = in.nextLong();

            StringBuilder s = new StringBuilder();
            s.append("FESTIVA");
            int idx = 0;
            while (k > 0 && idx + 1 < c.length) {
                int base = idx * 25 + 100;
                for (int i = base; i >= 100; i--) {
                    if (k % i < k % base) {
                        base = i;
                    }
                }
                for (int i = 0; i < k % base; i++) {
                    s.append("L");
                }

                for (int pos = c.length - 1; pos >= idx; pos--) {
                    for (int i = 0; i < base - 1; i++) {
                        s.append(c[pos]);
                    }
                }
                k /= base;
                idx++;
            }
            if (k > 0) {
                long sqrt = (long) (Math.sqrt(k));
                for (int i = 0; i < k % sqrt; i++) s.append("L");
                for (int i = 0; i < sqrt - 1; i++) s.append(c[idx]);
                k /= sqrt;
                while (k-- > 0) s.append("L");
            }
            out.println(s.toString());
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



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


int main(){
  int x,i,t;
  cin >> x;
  t=0;
  i=0;
  int su=0;
  while(su<x){
    su+=i;
    t=i;
    i++;
  }
  int ans=x;
  while((t*(t+1)/2)>=x){
    int cal=t*(t+1)/2;
    ans=min(ans,t);
    t--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
Ss = input()

N = len(Ss)
S1s = Ss[:N//2]
S2s = Ss[N//2+1:]
#print('S1s:', S1s)
#print('S2s:', S2s)

if Ss == Ss[::-1] and S1s == S1s[::-1] and S2s == S2s[::-1]:
    print('Yes')
else:
    print('No')


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

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

    int ssize = s.size();
    if(ssize < 4) {
        cout << 0 << endl;
    } else if(ssize == 4){
        cout << !(stoi(s)%2019) << endl;
    } else {
        ll ans = 0;
        ll cnt[200000];
        int num = 0; int digit = 1;

        rrep(i, ssize - 1) {
            num = (num + digit*(s[i] - '0'))%2019;
            digit = (digit*10)%2019;

            ans += cnt[num];
            if (!num) ans++;

            cnt[num]++;
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3772