akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
public class Main {
  public static void main(String[] args) {
    Main m = new Main();
    m.run();
  }
  private void run() {
    int n = 0;
    long c = 0;
    Sushi[] sushi = new Sushi[0];
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
      String[] s = br.readLine().split("\\s+");
      n = Integer.parseInt(s[0]);
      c = Long.parseLong(s[1]);
      sushi = new Sushi[n+2];
      sushi[0] = new Sushi(0L,0L);
      sushi[n+1] = new Sushi(0L,0L);
      for (int i=0;i<n;i++) {
        s = br.readLine().split("\\s+");
        sushi[i+1] = new Sushi(Long.parseLong(s[0]),Integer.parseInt(s[1]));
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    long m = 0;
    {
      long[] f = new long[n+2];
      long[] g = new long[n+2];
      for (int i=1;i<n+1;i++) {
        f[i] = f[i-1] + sushi[i].v;
      }
      for (int i=0;i<n+1;i++) {
        f[i] -= 2*sushi[i].x;
      }
      for (int i=1;i<n+1;i++) {
        g[i] = g[i-1];
        if (g[i] < f[i]) g[i] = f[i];
      }
      long s = 0;
      for (int i=n;i>0;i--) {
        s += sushi[i].v;
        long t = g[i-1] + s - (c-sushi[i].x);
        if (m < t) m = t;
      }
    }
    {
      long[] f = new long[n+2];
      long[] g = new long[n+2];
      for (int i=n;i>0;i--) {
        f[i] = f[i+1] + sushi[i].v;
      }
      for (int i=n+1;i>0;i--) {
        f[i] -= 2*(c-sushi[i].x);
      }
      for (int i=n;i>0;i--) {
        g[i] = g[i+1];
        if (g[i] < f[i]) g[i] = f[i];
      }
      long s = 0;
      for (int i=1;i<n+1;i++) {
        s += sushi[i].v;
        long t = g[i+1] + s - sushi[i].x;
        if (m < t) m = t;
      }
    }
    System.out.println(m);
  }
  private class Sushi {
    private long x;
    private long v;
    Sushi(long x,long v) {
      this.x = x;
      this.v = v;
    }
  }
}

Measured memory_bytes: 65852
/*..............................................*\
Author:Kishor Kumar Paroi
Dept:CSE-1703053
email.kishor.josephite@gmail.com
RUET,BANGLADESH
\*---------------------------*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include<bits/stdc++.h>
#include<iostream>
#include<iterator>

#define max(a,b) ((a>b)?a:b)                        //finding max
#define min(a,b) ((a<b)?a:b)                        //finding min
#define Max(a,b,c) max(a,max(b,c))                  //finding max between 3 numbers
#define Min(a,b,c) min(a,min(b,c))                  //finding min between 3 numbers
#define Pi acos(-1.0)                               //defining Pi for mathematical uses
#define Clear(a) memset(a,0,sizeof(a))              //clearing memory of an array
#define setfalse(a) memset(a,false,sizeof(a))       //setting the array into false
#define settrue(a) memset(a,true,sizeof(a))         //setting the array into true
#define clrstr(a) memset(a,'\0',sizeof(a))          //setting string array to null
#define open freopen("input.txt","r",stdin)         //opening input file
#define close freopen ("output.txt","w",stdout)     //opening output file
#define Case(a) printf("Case %d: ",a)               //printing case number
#define caseh(a) printf("Case #%d: ",a)             //printing case number having '#'
#define getcase(a) scanf("%d",&a)                   //scanning case number
#define caseloop(a,b) for(a=1;a<=b;a++)             //making case loop
#define EPS 1e-9                                    //small value for avoiding preccesion error
#define LL long long                                //long long short form
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

//const int N=100*1000;
//const int mod=1e9+7;

//# define int min3(int a,int b,int c){return min(a,min(b,c));}
//#define int max3(int a,int b,int c){return max(a,max(b,c));}
//#define int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
//#define int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    int a= stoi(s.substr(0,2));
    int b=stoi(s.substr(2,2));
    //cout<<a<<endl;
    //cout<<b<<endl;
    int y=0,m=0;
    if(1<=a &&a<=12)
        m=1;
    if(1<=b && b<=12)
        y=1;
    if(y==1&&m==1)
    {
        cout << "AMBIGUOUS" << endl;
        return 0;
    }
    if(y==1)
    {
        cout << "YYMM" << endl;
        return 0;
    }
    if(m==1)
    {
        cout << "MMYY" << endl;
        return 0;
    }
    cout << "NA" << endl;
    return 0;
}



Measured memory_bytes: 256
x, y = map(int, input().split())
group_a = [1, 3, 5, 7, 8, 10, 12]
group_b = [4, 6, 9, 11]
group_c = [2]

if x in group_a and y in group_a:
    print('Yes')
elif x in group_b and y in group_b:
    print('Yes')
elif x in group_c and y in group_c:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <climits>

using namespace std;

int main() {
	int i, j, k, to, min, temp_result;
	int n;
	int r[100], c[100];
	int result[100][100];
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> r[i] >> c[i];
		result[i][i] = 0;
	}
	
	i = 0;
	j = 1;
	to = n - 2;
	while (j <= n - 1) {
		while (i <= to) {
			//computation of result[i][i+j]
			min = INT_MAX;
			k = i;
			while (k <= i + j - 1) {
				temp_result = c[k] * r[i] * c[i + j] + result[i][k] + result[k + 1][i + j];
				if (temp_result < min) {
					min = temp_result;
				}
				k++;
			}
			result[i][i + j] = min;
			i++;
		}
		i = 0;
		j++;
		to--;
	}
	printf("%d\n", result[0][n - 1]);
}

Measured memory_bytes: 1184
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
using namespace std;

typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

int solve(int num){
    return (num + 1)*num/2;
}


int main(){
    int N,K;
    cin >> N >> K;
    vector<int> p(N);
    vector<double> pn(N);
    vector<double> psum(N);
    double ans;
    int tmp1;
    cin >>tmp1;

    cout << fixed;
    cout << setprecision(10);
    p[0]=tmp1;
    pn[0]=double(tmp1+1)/double(2);
    psum[0]=double(pn[0]);
    // cout<< p[0]<<":"<<pn[0]<<endl;
    for(int i =1;i<N;i++){
        int tmp;
        cin>>tmp;
        p[i]= tmp;
        pn[i] = double(tmp+1)/double(2);
        psum[i] = pn[i]+psum[i-1];

        // cout<< p[i]<<":"<<pn[i]<<endl;
    }
    
   
    
    ans = psum[K-1];
    for (int i = K; i < N; i++){
        ans = max(ans,psum[i]-psum[i-K]);
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 4096
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = 10**9 + 7

dp = [[0 for _ in range(k+1)] for __ in range(n)]

sm = 0

for i in range(n):
    sm += a[i]
    for j in range(k+1):
        if j == 0:
            dp[i][j] = 1
            continue
        if sm < j:
            dp[i][j] = 0
        else:
            if j-1-a[i] >= 0:
                dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1-a[i]]
            else:
                dp[i][j] = dp[i][j-1] + dp[i-1][j]
            dp[i][j] %= mod

print(dp[n-1][k])


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

int ar[100005];
int main(){
	int len, n;
	scanf("%d %d", &len, &n);
	string s;
	cin >> s;
	int cnt = 0;
	for(int i = 0; i < len; i++){
		if(s[i]=='A') cnt=1;
		else if(s[i]=='C' && cnt>0) cnt++;
		else cnt = 0;

		ar[i] = ar[i-1]+cnt/2;
		if(cnt/2 == 1) cnt = 0;
		cerr << ar[i] << endl;	
	}

	for(int i = 0; i < n; i++){
		int l, r;
		scanf("%d%d", &l,&r);
		l--;r--;
		printf("%d\n", ar[r]-ar[l]);
	}
	
	return 0;
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define answer(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

Int modpow(Int a, Int n, Int mod) {
    Int ret = 1;
    while (n > 0) {
        if (n & 1) {
            ret = ret * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }

    return ret;
}

vector<Int> factorials(0), invs(0);
bool is_ncr_table = false;
void calc_ncr_table(Int n, Int mod) {
    is_ncr_table = true;

    // 1! ~ n! の計算
    Int f = 1;
    factorials.push_back(f);
    for (Int i = 1; i < n + 1; i++) {
        f *= i;
        f %= mod;
        factorials.push_back(f);
    }
    // n!^-1 の計算
    Int inv = modpow(factorials[n], mod - 2, mod);
    // (n-1)!^-1 ~ 1!^-1 の計算
    invs.assign(n, 1);
    invs[n] = inv;
    for (Int i = n; i >= 1; i--) {
        inv *= i;
        inv %= mod;
        invs[i - 1] = inv;
    }
}

Int factorial(Int n, Int mod = 1) {
    Int ret = 1;
    if (mod == 1) {
        for (Int i = 1; i < n + 1; i++) {
            ret *= i;
        }

        return ret;
    } else {
        for (Int i = 1; i < n + 1; i++) {
            ret *= i;
            ret %= mod;
        }

        return ret;
    }
}

Int ncr(Int n, Int r, Int mod, bool use_table = false) {
    if (use_table) {
        // modが素数の場合のみ
        if (!is_ncr_table) {
            calc_ncr_table(n, mod);
        }
        return factorials[n] * invs[r] * invs[n - r] % mod;
    } else {
        Int x = 1;
        for (Int i = n - r + 1; i < n + 1; i++) {
            x *= i;
            x %= MOD;
        }
        return x * modpow(factorial(r, mod), mod - 2, mod) % mod;
    }
}

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

    vector<int> dif(N);
    for (int i = 1; i < N; i++) {
        dif[i] = A[i] - A[i - 1];
    }
    dif[0] = K - A[N - 1] + A[0];
    sort(dif.begin(), dif.end());

    cout << K - dif[N - 1] << endl;

    return 0;
}

Measured memory_bytes: 1792
'use strict';
process.stdin.on('data', function(chunk) {
  var inputs = chunk.toString().trim().split(' ');
  var a = Number(inputs[0]);
  var b = Number(inputs[1]);
  console.log(a*b,(a+b)*2);

});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15512
#include <bits/stdc++.h>
using namespace std;
int ceiling(int p, int q) {
	return (p % q == 0) ? (p / q) : ((p / q) + 1);
}

int main (int argc, char const* argv[])
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	int pos = 0;
	for(int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		if(x == 1) {
			pos = i;
		}
	}	
	int ans = n;
	for(int i = max(pos - k + 1, 1); i <= pos && i + k - 1 <= n; i++) {	
		int p = i;
		int q = i + k - 1;
		int res = 1;
		res += ceiling(p-1, k-1);
		res += ceiling(n-q, k-1);
		ans = min(ans, res);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np


def main():
	#N, D = [int(x) for x in input().split()]
	N = int(input()) + 1
	a = [0]
	a += [int(x) for x in input().split()]
	b = [0] * (len(a))

	counter = 0
	for i in range(N-1, 0, -1):
		num = 0
		for j in range(i, N, i):
			num += b[j]
		if not num % 2 == a[i]:
			b[i] += 1
			counter += 1
	if max(b) > 1:
		print(-1)
		return
	print(counter)
	l = [i for i, x in enumerate(b) if x == 1]
	for row in l:
		print(row, end=" ")
	print("")

if __name__ == "__main__":
	main()


Measured memory_bytes: 21040
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,maxi=0,f=0,mini=INF,sum=0,q;
	string str,g;
    cin>>a>>b>>c;
    if((a*100+b*10+c)%4==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


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

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

X, Y = ds_in()

x = bin(X)[2:]
y = bin(Y)[2:]
xl = len(x)
yl = len(y)


def bit_compare(A, B):
    """ 
    A, B: str 
    
    Return
    ------
    A >= B
    """
    flag = True
    for a, b in zip(A, B):
        if int(a) != int(b):
            if int(a) > int(b):
                flag = True
            else:
                flag = False
            break
    return flag


if bit_compare(y[:xl], x):
    print(yl - xl + 1)
else:
    print(yl - xl)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,M;cin >> N >> M;
  vector<vector<int> > v(N,vector<int> (M));
  rep(i,N)rep(j,M){
    cin >> v[i][j];
    --v[i][j];
  }
  //参加人数がX人以下となるようにできるか．
  auto f = [&](int X){
    //j番目のスポーツのプレイ人数
    vector<int> w(M);
    vector<bool> open(M,true);
    while(true){
      rep(i,M)w[i] = 0;
      rep(i,N){
        int play = M+1;
        rep(j,M){
          if(!open[v[i][j]])continue;
          play = v[i][j];
          break;
        }
        if(play == M+1) return false;
        ++w[play];
      }
      bool sat = true;
      rep(j,M) if(w[j] > X){
        sat = false;
        open[j] = false;
      }
      if(sat)return true;
    }
    return false;
  };
  int l = 0, r = N;
  while(r-l>1){
    int m = (l+r)/2;
    if(f(m))r = m;
    else l = m;
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	register char addr = 0;
	char in, stack[10];
	for (;;) {
		scanf("%d", &in);
		if (in)
			stack[addr++] = in;
		else {
			if (!addr)
				return 0;
			else
				printf("%d\n", stack[--addr]);
		}
	}
}

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


int main() {
    long long n,d,x;
    cin >> n;
    x=1;
    for(d=1;d*d<=n;d++)
    {
        if(n%d==0)
        {
            x=d;
        }
    }
    cout << (x-1)+(n/x-1);
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        map: [Chars; h],
    }
    let mut ans = true;
    'outer: for i in 0..h {
        if i == h - 1 {
            for j in 0..w {
                if j >= 1 && map[i - 1][j] == '#' && map[i][j - 1] == '#' {
                    ans = false;
                    break 'outer;
                }
            }
            break 'outer;
        }
        for j in 0..w {
            if map[i][j] == '.' {
                continue;
            }
            if j == w - 1 {
                if i >= 1 && map[i][j - 1] == '#' && map[i - 1][j] == '#' {
                    ans = false;
                    break 'outer;
                }
                continue;
            }
            if map[i + 1][j] == '#' && map[i][j + 1] == '#' {
                ans = false;
                break 'outer;
            }
        }
    }
    if ans {
        println!("Possible");
    } else {
        println!("Impossible");
    }
}


Measured memory_bytes: 2168
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    A_ = [int(input()) for _ in range(N)]

    max_A = max(A_)
    if A_.count(max_A) > 1:
        for i in range(N):
            print(max_A)
            
    else:
        for i in range(N):
            if A_[i] == max_A:
                L = A_[0:i]
                L.extend(A_[i+1:])
                print(max(L))
            else:
                print(max_A)

                
if __name__ == "__main__":
    main()


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

int main() {
	int n, m, k; cin >> n >> m >> k;
	bool ok = false;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (i * (m - j) + (n - i) * j == k) ok = true;
		}
	}
	if (ok) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 3644
import std;

auto input()
{
    return readln().chomp();
}

alias sread = () => readln.chomp();

void main()
{
    long N;
    scan(N);
    // writeln(N);
    long 今の時間 = 0;
    long 今のx座標 = 0;
    long 今のy座標 = 0;
    long dist = 0;
    bool check = true;
    long time = 0;
    foreach (i; 0 .. N)
    {
        long T, X, Y;
        scan(T, X, Y);
        // writeln(T, X, Y);
        time = T - 今の時間; //3=6-0
        // writeln("TT:", T);
        // writeln("tt", t);
        // writeln("time", time);
        dist = abs(X - 今のx座標) + abs(Y - 今のy座標);
        //writeln("dist:", dist);

        if (dist > time)
        {
            check = false;

        }
        if ((time - dist) % 2 != 0)
        {

            check = false;

        }
        今のx座標 = X;
        今のy座標 = Y;
        今の時間 = T;

    }
    if (check)
    {
        writeln("Yes");
    }
    else
    {
        writeln("No");
    }

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}


Measured memory_bytes: 4488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define FLASH ios::sync_with_stdio(0);cin.tie(0);
#define all(v)  v.begin(),v.end()
const int inf=1e9+7;
const int mod=1e9+7;
const ll INF=1e18;	

bool sz(int a,int b)
{
	return a>b;
}

						void solve()
						{
							
							ll x,y;
							cin>>x>>y;
							
							if(x%y==0)
							{
								cout<<-1;
							}
							else
							{
								cout<<x;
							}
							
								
						
						}




int main()
{	
	FLASH
	int t=1;
	
	while(t--)
	{
		solve();
	}
	
}

Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int p[10+5],c[10+5];
int d,g,ans=1e9;
int main()
{
	scanf("%d%d",&d,&g);
	for(int i=0;i<d;i++)
		scanf("%d%d",&p[i],&c[i]);
	for(int f=0;f<(1<<d);f++)
	{
		int s=0,num=0,Max=-1;
		for(int i=0;i<d;i++)
		{
			if(f>>i&1)
			{
				s+=100*(i+1)*p[i]+c[i];
				num+=p[i];
			}
			else
				Max=i;
		}
		if(s<g)
		{
			int s1=100*(Max+1);
			int need=(g-s+s1-1)/s1;
			if(need>=p[Max])
				continue;
			num+=need;
		}
		ans=min(ans,num);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
sm = sum(a)
ac = Counter(a)
q = int(input())
for i in range(q):
   b,c = map(int,input().split())
   delta = ac[b] * (c-b)
   ac[c] += ac[b]
   ac[b] = 0
   sm += delta
   print(sm)

Measured memory_bytes: 24124
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n;
double x[55], y[55], ox, oy, d, EPS = 1e-7, ans = 2000;
inline double dis(double x, double y){return x*x+y*y;};
int main(){
	scanf("%d", &n);
	rep(i,n) scanf("%lf%lf", x+i, y+i);
	rep(i,n) rep(j,i){
		bool ok = true;
		ox = (x[i]+x[j]) / 2;
		oy = (y[i]+y[j]) / 2;
		d = dis(ox-x[i],oy-y[i]);
		rep(k,n) if(d + EPS < dis(ox-x[k],oy-y[k])) ok = false;
		if(ok) ans = min(ans, sqrt(d));
		else{
			rep(k,j){
				bool ok = true;
				double x1 = x[k]-x[i], x2 = x[k]-x[j], y1 = y[k]-y[i], y2 = y[k]-y[j], x3 = (x[k]+x[i])/2, x4 = (x[k]+x[j])/2, y3 = (y[k]+y[i])/2, y4 = (y[k]+y[j])/2;
				if(abs(x1*y2 - x2*y1) < EPS) continue;
				double t = ((x3 - x4) * x2 + (y3 - y4) * y2) / (x1*y2 - x2*y1);
				ox = t * y1 + x3;
				oy = -t * x1 + y3;
				d = dis(ox-x[i],oy-y[i]);
				rep(l,n) if(d + EPS < dis(ox-x[l],oy-y[l])) ok = false;
				if(ok) ans = min(ans, sqrt(d));
			}
		}
	}
	printf("%.9lf\n", ans);
}

Measured memory_bytes: 256
#include<cstdio>

int n,m;
inline int lowbit(int x) {
	return x&(x-1);
}
inline void Pt(int u,int v) {
	printf("%d %d\n",u,v);
}
int main() {
	scanf("%d",&n);
	if(lowbit(n)==0) {
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	for(int i=1;i<=2;i++)
		Pt(i,i+1),Pt(n+i,n+i+1);
	Pt(3,n+1);
	if(n%2==0)
		m=n--;
	else m=n;
	for(int i=4;i<=n;i++)
		Pt(1,i),Pt(i,m+(i^1));
	if(m>n) {
		int p=lowbit(m);
		Pt(m,p+1),Pt(m-p,2*m);
	}
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll x[5];
    ll ans = 0;
    rep(i, 5){
        cin >> x[i];
        if(x[i] == 0)ans = i+1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define pb push_back 
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORi(i,a,b) for(int i=a;i<b;i++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define print(a) for(auto x:a) cout<<x<<' ';cout<<endl;
#define printM(b) for(auto y:b) {print(y);}
#define printP(p) cout<<p.first<<' '<<p.second<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
template <typename T> 
T cmax(T x, T y) 
{ 
   return (x > y)? x: y; 
} 
 
void solve()

{
  ll n,k,t1,t2,ans=0;
  cin>>n>>k;
  while(n--)
  {

    cin>>t1>>t2;
    
    if(t1* t1+t2*t2 <=k*k )
    {
      ans++;
    }

  }
cout<<ans;
}
int main()
{
 
  fast;
  int t=1;
//cin>>t;
  while(t--){
 
solve();
cout<<endl;
  }
 
 
  
  return 0;
}

Measured memory_bytes: 3616
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()

from collections import defaultdict
edges = defaultdict(set)
for i in range(M):
    u, v = nl()
    edges[u].add(v+N)
    edges[u+N].add(v+2*N)
    edges[u+2*N].add(v)

S, T = nl()

import queue
q = queue.Queue()
q.put((S, 0))

done = [False] * (3*N+1)
done[S] = True

while not q.empty():
    src, cost = q.get()
    for dst in edges[src]:
        if dst == T:
            print((cost+1) // 3)
            import sys
            sys.exit()

        if not done[dst]:
            done[dst] = True
            q.put((dst, cost+1))

print(-1)




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

int main()
{
	int N,K,i,sum;
	scanf(" %d%d",&N,&K);
	sum = 1;
	for(i = 1; i <= N ;i++)
	{
		if(K >= sum)
		{
			sum = sum * 2;
		}
		else
		{
			sum = sum + K;
		}
	}
		printf("%d",sum);
}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
using namespace std;
const int maxn = 107; 
int main()
{
	string ss[maxn], ans[maxn];
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; ++i) {
		cin >> ss[i];
		ans[i] = ss[i];
	}
	for (int i = 0; i < h; ++i) {
		bool fg = true;
		for (int j = 0; j < w; ++j) if (ss[i][j] != '.') {
			fg = false;
			break;
		}
		if(fg) {
			for (int j = 0; j < w; ++j) {
				ans[i][j] = ' ';
			}
		}
	}
	for (int j = 0; j < w; ++j) {
		bool fg = true;
		for (int i = 0; i < h; ++i) if(ss[i][j] != '.') {
			fg = false;
			break;
		}
		if(fg) {
			for (int i = 0; i < h; ++i) {
				ans[i][j] = ' ';
			}
		}
	}
	for (int i = 0; i < h; ++i) {
		bool fg = false;
		for (int j = 0; j < w; ++j) if(ans[i][j] != ' ') {
			cout << ans[i][j];
			fg = true;
		}
		if(fg) cout << endl;
	} 
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int x,a,b,c;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        x = sc.nextInt();
        int cnt=0;
        for(int i=0;i<=a;i++)
        {
            for(int j=0;j<=b;j++){
                int sum = i*500+j*100;
                if(sum==x)cnt++;
                else if(x>sum&&(x-sum)%50==0&&(x-sum)/50<=c)cnt++;
            }
        }
        
        System.out.println(cnt);
        
    }
}

Measured memory_bytes: 23892
import java.util.Scanner;

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

        String line = sc.next();
        int a = Integer.parseInt(line);
        line = sc.next();
        int b = Integer.parseInt(line);

        if(a < b){
            System.out.println("a < b");
        }else if(a > b){
            System.out.println("a > b");
        }else{
            System.out.println("a == b");
        }
        sc.close();
    }


}


Measured memory_bytes: 25964
import heapq
l,r = map(int,input().split())
mod = 2019
ans = 2018
if r-l>=2018:
    print(0)
else:
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            ans = min(ans,(i*j)%mod)
    print(ans)

Measured memory_bytes: 3060
import java.util.*;
public class Main {
  public static void main(String[] args) {
   Scanner scan = new Scanner(System.in);
   int n = scan.nextInt();
   int[] l = new int[n];
   
   for(int i = 0; i < n ; i++){
       l[i] = scan.nextInt();
   }
   for (int i = l.length - 1; i >= 0; i--) {
            System.out.print( l[i] );
if(i != 0){
        System.out.print(" ");
    }
        } 
System.out.println();
  }
}


Measured memory_bytes: 26268
[<EntryPoint>]
let main argv =
    let nk = System.Console.ReadLine().Split()
    let n = nk.[0] |> int
    let k = nk.[1] |> int
    let hx = System.Console.ReadLine().Split() |> Array.map int
    let ans =
        hx
        |> Array.filter (fun x -> x >= k)
        |> Array.length
    System.Console.WriteLine(ans)
    0


Measured memory_bytes: 18912
//
//  main.cpp

#include <iostream>
#include <queue>
using namespace std;
using ll = long long;
int h,w,n;
bool matrix[1001][1001]={{}};
bool visited[1001][1001]={{}};
pair<int,int> target;
struct state{
	int x;
	int y;
	int depth;
};

ll min(ll x,ll y){
	if(x < y){
		return x;
	}else{
		return y;
	}
}

/*

ll dfs(ll depth,int x,int y){
	if(!matrix[x][y])return MAX;
	if(target.first == x && target.second == y)return depth;
	
	ll a,b,c,d;
	a = b = c = d = MAX;
	if(!visited[x+1][y]){
		visited[x+1][y] = true;
		a = dfs(depth+1,x+1,y);
		visited[x+1][y] = false;
	}
	if(!visited[x-1][y]){
		visited[x-1][y] = true;
		b = dfs(depth+1,x-1,y);
		visited[x-1][y] = false;
	}
	if(!visited[x][y+1]){
		visited[x][y+1] = true;
		c = dfs(depth+1,x,y+1);
		visited[x][y+1] = false;
	}
	if(!visited[x][y-1]){
		visited[x][y-1] = true;
		d = dfs(depth+1,x,y-1);
		visited[x][y-1] = false;
	}
	return min(a,min(b,min(c,d)));
}
*/
ll bfs(int x,int y){
	queue<state> willvisit;
	willvisit.push({x,y,0});
	ll ret;
	while(1){
		state now = willvisit.front();
		willvisit.pop();
		
		if(now.x == target.first && now.y == target.second){
			ret = now.depth;
			break;
		}
		
		if(!visited[now.x+1][now.y]){
			if(matrix[now.x+1][now.y]){
				visited[now.x+1][now.y] = true;
				willvisit.push({now.x+1,now.y,now.depth+1});
			}
		}
		if(!visited[now.x-1][now.y]){
			if(matrix[now.x-1][now.y]){
				visited[now.x-1][now.y] = true;
				willvisit.push({now.x-1,now.y,now.depth+1});
			}
		}
		if(!visited[now.x][now.y+1]){
			if(matrix[now.x][now.y+1]){
				visited[now.x][now.y+1] = true;
				willvisit.push({now.x,now.y+1,now.depth+1});
			}
		}
		if(!visited[now.x][now.y-1]){
			if(matrix[now.x][now.y-1]){
				visited[now.x][now.y-1] = true;
				willvisit.push({now.x,now.y-1,now.depth+1});
			}
		}
	}
	
	return ret;
}

void visitedReset(){
	for(int i=0;i<1001;i++){
		for(int j=0;j<1001;j++){
			visited[i][j] = false;
		}
	}
}

int main(){
	for(int i=0;i<1001;i++){
		for(int j=0;j<1001;j++){
			matrix[i][j] = visited[i][j] = false;
		}
	}
	
	cin >> h >> w >> n;
	pair<int,int> cheese[10];
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			char input;
			cin >> input;
			switch(input){
				case '.':
					matrix[i][j] = true;
					break;
				case 'X':
					matrix[i][j] = false;
					break;
				case 'S':
					matrix[i][j] = true;
					cheese[0] = make_pair(i,j);
					break;
				default:
					matrix[i][j] = true;
					cheese[input - '0'] = make_pair(i,j);
					break;
			}
		}
	}
	
	ll answer=0;
	for(int i=0;i<n;i++){
		target = cheese[i+1];
		visited[cheese[i].first][cheese[i].second] = true;
		
		answer += bfs(cheese[i].first,cheese[i].second);
		visitedReset();
	}
	/*
	for(int i=0;i<n;i++){
		target = cheese[i+1];
		visited[cheese[i].first][cheese[i].second] = true;
		answer += dfs(0,cheese[i].first,cheese[i].second);
		visited[cheese[i].first][cheese[i].second] = false;
	}
	*/
	cout << answer << endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;	string S;	cin>>N>>S;
	N%=26;
	while(N--){
		FOR(i,0,S.size()){
		if(S[i]=='Z')	S[i]='A';
        else S[i]++;
		}
	}

  cout<<S<<endl;
  
    return 0;
}




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

int K, S;
int count = 0;

void solve() {
  for(int i = 0; i<= K; i++) {
    for(int j = 0; j <= K; j++) {
      if(0 <= S - i - j && S - i - j <= K) count++;
    }
  }
}



int main() {
  cin >> K >> S;
  solve();
  cout << count << endl;
  return 0;
}

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

int main() {
    string s; cin >> s;
    if (s == "AAA" || s == "BBB") {
        puts("No");
    }
    else
        puts("Yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    int main() {
string s,t,u;
int a,b;

cin>>s>>t;
cin>>a>>b;
cin>>u;
if(u[0]==s[0]){
    a=a-1;
}else{
    b=b-1;
}
cout<<a<<" "<<b;

        return 0;
    }



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

int main(void){
    vector<vector<char>> c(3, vector<char>(3));
    for (int i=0; i<3; i++){
        for (int j=0; j<3; j++){
            cin >> c[i][j];
        }
    }
    cout << c[0][0] << c[1][1] << c[2][2] << endl;
    return 0;
}

Measured memory_bytes: 3628
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("No");exit(0);}
	
	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int M=5e6+10;
	ll fac[M],facinv[M],Inv[M];ll C(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,M-1) fac[i]=fac[i-1]*i%MOD;
		facinv[M-1]=invm(fac[M-1]);fd(i,M-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,M-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=1e6+10;
	//------------------FIXED------------------
	int fa[N],dis[N];int findfa(int x){if(fa[x]==x)return x;int ff=fa[x];fa[x]=findfa(ff),dis[x]+=dis[ff];return fa[x];}
	void main()
	{
		int n=qread(),m=qread();fo(i,1,n) fa[i]=i,dis[i]=0;
		while(m--)
		{
			int x=qread(),y=qread(),d=qread();
			int fx=findfa(x),fy=findfa(y);
			if(fx<fy) fa[fy]=fx,dis[fy]=d+dis[x]-dis[y];
			else if(fy<fx) fa[fx]=fy,dis[fx]=dis[y]-(dis[x]+d);
			else if(dis[y]-dis[x]!=d) GG();
		}puts("Yes");
	}
};//����������
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();//����Ԥ����ģ����
	mine::main();
	debug("\n---------------------Zory---------------------\nTime: %.2lf s",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 123776
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush,heapify
from bisect import bisect_left

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    q = []
    for i in range(M):
        B, C = map(int, input().split())
        heappush(q,(-C,B))
    
    ans = 0
    index = 0
    # print(A)
    while q:
        c,b = heappop(q)
        c *= -1
        # print(c,b)
        count = 0
        for i in range(b):
            if i + index == N:
                break
            if c > A[index+i]:
                ans += c
                count += 1
            else:
                break

        # print(ans,index)
        if count < b:
            index += count
            break
        else:
            index += count
            
    print(ans + sum(A[index:]))

if __name__ == "__main__":
    main()


Measured memory_bytes: 21448
#include <iostream>
#include <string>
#include <vector>
#include <ios>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
  string s;
  cin >> s;
  
  long long n = s.length();
  vector<long long>a(n,0);
  
  long long p = 0;
  long long count = 1;
  long long now = 0;
  long long ans = 0;
  
  while(now < n){
      while(s[now] == s[now + 1]){
          count++;
          now++;
      }
  a[p] = count;
  p++;
  count = 1;
  now++;
  }
  
  if(s[0] == '<'){
  
  for(long long i=0;i<p/2;i++){
      long long x,y;
      x = max(a[i * 2],a[i * 2 + 1]);
      y = min(a[i * 2],a[i * 2 + 1]) - 1;
      ans += x * (x + 1) / 2;
      ans += y * (y + 1) / 2;
  }
  
  if(p % 2 != 0){
      ans += a[p - 1] * (a[p - 1] + 1) / 2;
  }
  
  cout << ans << endl;
  }
  else{
      ans += a[0] * (a[0] + 1) / 2;
      
    if(p % 2 != 0){
        for(long long i=0;i<=p/2 - 1;i++){
      long long x,y;
      x = max(a[i * 2 + 1],a[i * 2 + 2]);
      y = min(a[i * 2 + 1],a[i * 2 + 2]) - 1;
      ans += x * (x + 1) / 2;
      ans += y * (y + 1) / 2;
        }
    }
    if(p % 2 == 0){
        for(long long i=0;i<p/2 - 1;i++){
      long long x,y;
      x = max(a[i * 2 + 1],a[i * 2 + 2]);
      y = min(a[i * 2 + 1],a[i * 2 + 2]) - 1;
      ans += x * (x + 1) / 2;
      ans += y * (y + 1) / 2;
        }
    }
  
  if(p % 2 == 0){
      ans += a[p - 1] * (a[p - 1] + 1) / 2;
  }
  
  cout << ans << endl;
  }
  
  return 0;
}

  


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

using namespace std;

int main(){
    int a; //aを定義
    string s; //sを定義
    cin >> a;
    cin >> s;
    /*for(int i = 1; i < a; i++){*/
        if(a >= 3200){
            cout << s << endl;
        }else if(a < 3200){
            cout << "red" << endl;
        }
    }

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

using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    for(int i=1;i<1000000000;i++)
    {
        if(abs(x-i)==abs(y-i))
        {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  while(getline(cin,str)){
    while(str.find("the")==-1&&str.find("this")==-1&&str.find("that")==-1){
      int i;
      for(i=0;i<str.size();i++){
    if('a'<=str[i]&&str[i]<'z') str[i]++;
    else if(str[i]=='z') str[i]='a';
      }
    }
    cout << str << endl;
  }
  return 0;
}


Measured memory_bytes: 2996
#include<queue>
#include<cstdio>
#include<algorithm>

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

using namespace std;

template<class T>
struct interval{
	T a,b,w;
	interval():a(0),b(0){}
	interval(const T &a,const T &b):a(a<b?a:b),b(a<b?b:a){}
	bool operator<(const interval &I)const{ return b<I.b || b==I.b && a<I.a; }
};

const int V_MAX=2003;
const int CAPA_INF=1<<29;
const int COST_INF=1<<29;

template<class T,class U>
struct edge{
	int v,rev;
	T capa;
	U cost;
	T flow;
};

template<class T,class U>
void add_directed_edge(vector< edge<T,U> > *G,int u,int v,T capa,U cost){
	G[u].push_back((edge<T,U>){v,G[v].size()  ,capa, cost,0});
	G[v].push_back((edge<T,U>){u,G[u].size()-1,   0,-cost,0});
}

template<class T,class U>
pair<T,U> augment(int n,vector< edge<T,U> > *G,int s,int t,U *pot,bool fir){
	static int pre[V_MAX];
	static U d[V_MAX];
	rep(u,n) d[u]=(u==s?0:COST_INF);

	bool ok;
	if(fir){
		// Bellman-Ford
		while(1){
			bool end=true;
			rep(u,n) rep(i,G[u].size()) {
				edge<T,U> &e=G[u][i];
				if(e.capa-e.flow>0 && d[u]<COST_INF && d[u]+e.cost<d[e.v]){
					d[e.v]=d[u]+e.cost;
					pre[e.v]=e.rev;
					end=false;
				}
			}
			if(end) break;
		}
		ok=(d[t]<COST_INF);
	}
	else{
		// Dijkstra
		ok=false;
		priority_queue< pair<U,int> > Q; Q.push(make_pair(0,s));
		while(!Q.empty()){
			int u=Q.top().second;
			U cost=-Q.top().first; Q.pop();

			if(cost<d[u]) continue;
			if(u==t) ok=true;

			rep(i,G[u].size()){
				edge<T,U> &e=G[u][i];
				U cost2=cost+e.cost+pot[u]-pot[e.v];
				if(e.capa-e.flow>0 && cost2<d[e.v]){
					d[e.v]=cost2;
					pre[e.v]=e.rev;
					Q.push(make_pair(-cost2,e.v));
				}
			}
		}
	}

	if(!ok) return make_pair(0,0);

	T water=CAPA_INF;
	for(int v=t;v!=s;){
		edge<T,U> &e1=G[v][pre[v]];
		edge<T,U> &e2=G[e1.v][e1.rev];
		water=min(water,e2.capa-e2.flow);
		v=e1.v;
	}

	U cost=0;
	for(int v=t;v!=s;){
		edge<T,U> &e1=G[v][pre[v]];
		edge<T,U> &e2=G[e1.v][e1.rev];
		e1.flow-=water;
		e2.flow+=water;
		cost+=water*e2.cost;
		v=e1.v;
	}

	rep(u,n) pot[u]+=d[u];

	return make_pair(water,cost);
}

template<class T,class U>
pair<T,U> primal_dual(int n,vector< edge<T,U> > *G,int s,int t){
	static U pot[V_MAX];
	rep(u,n) pot[u]=0;

	T ans1=0;
	U ans2=0;
	for(bool fir=true;;fir=false){
		pair<T,U> tmp=augment(n,G,s,t,pot,fir);
		if(tmp.first==0) break;
		ans1+=tmp.first;
		ans2+=tmp.second;
	}
	return make_pair(ans1,ans2);
}

int main(){
	for(int n;scanf("%d",&n),n;){
		interval<int> I[1000];
		rep(i,n) scanf("%d%d%d",&I[i].a,&I[i].b,&I[i].w);

		sort(I,I+n);

		int s=0,t=2*n+1;
		vector< edge<int,int> > G[V_MAX];
		rep(u,n) for(int v=u+1;v<n;v++) if(I[u].b<I[v].a) {
			add_directed_edge(G,1+2*u+1,1+2*v,1,-I[v].w);
		}
		rep(u,n){
			add_directed_edge(G,s,1+2*u,1,-I[u].w);
			add_directed_edge(G,1+2*u,1+2*u+1,1,0);
			add_directed_edge(G,1+2*u+1,t,1,0);
		}
		int tt=t+1;
		add_directed_edge(G,t,tt,2,0);

		printf("%d\n",-primal_dual(2*n+3,G,s,tt).second);
	}

	return 0;
}

Measured memory_bytes: 27384
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <deque>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    string S;
    cin >> S;
    vector<int> dp(2019,0);
    int ans = 0;
    for(int i=0;i<S.size();i++){
        vector<int> new_dp(2019,0);
        new_dp[S[i]-'0'] = 1;
        for(int j=0;j<2019;j++){
            new_dp[(j*10+(S[i]-'0'))%2019] += dp[j];
        }
        for(int j=0;j<2019;j++){
            dp[j] = new_dp[j];
        }
        ans += dp[0];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3752
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll a,b;
	cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b));
	return 0;
}

Measured memory_bytes: 256
data = input()
MOD = 10**9 + 7
SLen = len(data)
targets = "ABC"
array = [[0 for i in range(SLen + 1)] for _ in range(4)]
array[0][0] = 1
for i in range(SLen):
    for j in range(4):
        if data[i] == '?':
            if j < 3:
                array[j + 1][i + 1] = (array[j + 1][i + 1] + array[j][i]) % MOD
            array[j][i + 1] = (array[j][i + 1] + array[j][i] * 3) % MOD
        else:
            if j < 3 and data[i] == targets[j]:
                array[j + 1][i + 1] = (array[j + 1][i + 1] + array[j][i]) % MOD
            array[j][i + 1] = (array[j][i + 1] + array[j][i]) % MOD

print(array[3][SLen])


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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r) {
	if (l >= r)return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l, m);
	rec(m + 1, r);
	post.push_back(root);
}

void solve() {
	pos = 0;
	rec(0, pre.size());
	for (int i = 0; i < n; i++) {
		if (i)cout << " ";
		cout << post[i];
	}
	cout << endl;
}

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

	for (int i = 0; i < n; i++) {
		cin >> k;
		pre.push_back(k);
	}

	for (int i = 0; i < n; i++) {
		cin >> k;
		in.push_back(k);
	}
	solve();

	return 0;
}


Measured memory_bytes: 3152
#include <iostream>

using namespace std;

int main()
{
  int n;
  cin >> n;
  for (int i = 1; i <= 46300; i++)
    if (int(i * 1.08) == n)
      return cout << i << endl, 0;
  
  cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.*
import java.util.*

const val INF = 10000000000L
fun solve(N: Int, W: Int, w: IntArray, v: IntArray) {
    // dp[i][w] = iまで用いて重さwのときの最大の価値
    // dp[i][w] = max(dp[i-1][w], dp[i-1][w-w[i]] + v[i])
    val dp = Array(N){ LongArray(W+1){ -INF } }
    dp[0][0] = 0
    dp[0][w[0]] = v[0].toLong()
    for(i in 1 until N){
        for(j in 0..W){
            dp[i][j] = Math.max(dp[i-1][j], dp[i-1].getOrElse(j-w[i]){ -INF } + v[i])
        }
    }
    println(dp[N-1].max()!!)
    return
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val W = sc.next().toInt()
    val w = IntArray(N)
    val v = IntArray(N)
    for (i in 0 until N) {
        w[i] = sc.next().toInt()
        v[i] = sc.next().toInt()
    }
    solve(N, W, w, v)
}


Measured memory_bytes: 152552
//It doesn't matter how slow you go, Unless you don't stop.
#include<iostream>
#include<algorithm>
#include<bitset>
 
#include<cmath>
#include<cstring>
#include<climits>
 
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
 
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;
typedef map<LL,LL> mp64;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve()
{
    string s;cin>>s;
    int x=0,y=0;
    for(int i=0;i<3;i++)
    {
        if(s[i]=='A')
        {
            x++;
        }
        else
        {
            y++;
        }
    }
    if(x!=0 && y!=0)
    {
        cout<<"Yes"<<endl;
        return;
    }
    cout<<"No"<<endl;   
    
}
 
int main()
{
    DANGER;
    ofstream out("output.txt");
 
    auto start = chrono::high_resolution_clock::now();
    
    LL t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        solve();
    }
    
    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

Measured memory_bytes: 256