akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int m = sc.nextInt();

        int mina = Integer.MAX_VALUE;
        int[] arrA = new int[a];
        for(int i = 0;i < a;i++){
            arrA[i] = sc.nextInt();
            mina = Math.min(mina, arrA[i]);
        }
        int minb = Integer.MAX_VALUE;
        int[] arrB = new int[b];
        for(int i = 0;i < b;i++){
            arrB[i] = sc.nextInt();
            minb = Math.min(minb, arrB[i]);
        }

        int ans = mina + minb;
        for(int i = 0;i < m;i++){
            int x = sc.nextInt();
            int y = sc.nextInt();
            int c = sc.nextInt();

            ans = Math.min(ans, arrA[x-1] + arrB[y-1] - c);
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 132808
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Array
import Data.Char (digitToInt)

main :: IO ()
main = do
  xs <- inpi $ map digitToInt
  mapM_ (putStrLn . unwords . map show) $ solve xs

solve :: [[Int]] -> [[Int]]
solve = map puzzle

puzzle :: [Int] -> [Int]
puzzle xs = if null ys then [0] else ys
  where
    iarr = accumArray (+) 0 (1,9) $ (map (\x -> (head x, length x)) . group . sort) xs
    ys = filter (agari iarr) [1..9]
    
agari :: Array Int Int -> Int -> Bool
agari arr i = if arr ! i == 4 then False else findAg ars1
  where
    ar1 = accum (+) arr [(i,1)]
    ars1 = jantou ar1
    ag = accumArray (+) 0 (1,9) [(n,0) | n <- [1..9]]
    findAg xs | null xs = False
              | ag `elem` xs = True
              | otherwise = findAg ((concat [syuntsu a | a <- xs]) ++ (concat [koutsu a | a <- xs]))
    
jantou :: Array Int Int -> [Array Int Int]
jantou arr = [accum (-) arr [(i,2)] | i <- [1..9], arr ! i >= 2]

syuntsu :: Array Int Int -> [Array Int Int]
syuntsu arr = [accum (-) arr [(i,1),(i+1,1),(i+2,1)] | i <- [1..7], arr ! i >= 1, arr ! (i + 1) >= 1, arr ! (i + 2) >= 1]

koutsu :: Array Int Int -> [Array Int Int]
koutsu arr = [accum (-) arr [(i,3)] | i <- [1..9], arr ! i >= 3]

inpi :: (String -> a) -> IO [a]
inpi f = map f . lines <$> getContents

Measured memory_bytes: 4108
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

int main(){

	char ans_upper[9],ans_under[5];
	int upper,under,S;
	double number;

	while(true){
		scanf("%lf",&number);
		if(number < 0)break;

		upper = (int)floor(number);

		if(upper >= 256){
			printf("NA\n");
			continue;
		}

		S = 128;

		for(int i = 0; i < 8; i++){
			if(upper >= S){
				ans_upper[i] = '1';
				upper -= S;
			}else{
				ans_upper[i] = '0';
			}
			S /= 2;
		}

		ans_upper[8] = '\0';


		under = 10000*(number - (int)floor(number));

		for(int i = 0; i < 4; i++){
			under *= 2;
			if(under/10000 >= 1){
				ans_under[i] = '1';
			}else{
				ans_under[i] = '0';
			}
			under %= 10000;
		}

		if(under != 0){
			printf("NA\n");
			continue;
		}

		ans_under[4] = '\0';

		printf("%s.%s\n",ans_upper,ans_under);

	}

	return 0;
}

Measured memory_bytes: 2676
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

ll gcd(ll a, ll b);
ll lcm(ll a, ll b);

int main() {

    ll N;
    cin >> N;

    vector<ll>A(N), B(N);

    rep(i, N) {
        cin >> A[i] >> B[i];
    }

    ll count = 0;

    for (ll i = N - 1; i >= 0; i--) {
        A[i] += count;
        if (A[i] % B[i] != 0) {
            count += B[i] - (A[i] % B[i]);
        }
    }

    cout << count;

    return 0;
}


Measured memory_bytes: 4784
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let m: usize = sc.cin();

    let mut aced = vec![false; n];
    let mut pena = vec![0; n];

    for _ in 0..m {
        let k: usize = sc.cin::<usize>() - 1;
        let res: String = sc.cin();
        if res == "AC" {
            aced[k] = true;
        } else {
            if !aced[k] {
                pena[k] += 1;
            }
        }
    }

    let a = (0..n).filter(|&i| aced[i]).count();
    let b = (0..n).map(|i| if aced[i] { pena[i] } else { 0 }).sum::<i64>();
    put!(a, b);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;
 
int main(void){
    int n,k; cin >> n >> k;
    string s; cin >> s;
    s[k-1] = tolower(s[k-1]);
    cout << s << "\n";
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;

namespace diverta2019PC {
  class ProblemA {
    static void Main(string[] args) {
      int[] input = Input.nums;
      System.Console.WriteLine(input[0] - input[1] + 1);
    }
  }
  public class Input {
    public static string str => System.Console.ReadLine();
    public static string[] strs => str.Split(' ');
    public static char[] charArr => str.ToCharArray();
    public static int num => int.Parse(str);
    public static int[] nums => Array.ConvertAll(strs, int.Parse);
    public static long numL => long.Parse(str);
    public static long[] numLs => Array.ConvertAll(strs, long.Parse);
  }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void findNumberOfTriangles(vector<int> vec, int n)
{
    int count = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++)
                if (
                    vec[i] + vec[j] > vec[k]
                    && vec[i] + vec[k] > vec[j]
                    && vec[k] + vec[j] > vec[i]
                    && i < j && j<k && i<k
                    && vec[i]!=vec[j] && vec[i]!=vec[k] && vec[j]!=vec[k])
                    count++;
        }
    }
    cout <<count;
}
int main(){
    IOS;
    int t;
    cin >>t;
    vector<int> vec;
    for(int i=0; i<t; i++){
        int a;
        cin >> a;
        vec.push_back(a);
    }
    findNumberOfTriangles(vec,vec.size());
}


Measured memory_bytes: 3656
#include <cstdio>

typedef long long ll;
#define maxn 200010
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (-(_x)) : (_x))
int a[maxn]; ll s[maxn];
int main()
{
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", a + i), s[i] = s[i - 1] + a[i];
	ll ans = ~0ULL >> 1;
	for (int i = 1; i < n; ++i)
		cmin(ans, cabs(s[i] - s[n] + s[i]));
	printf("%lld\n", ans );
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
int main(void){
	int e1,e2,e3,e4;
	scanf("%d %d %d %d",&e1,&e2,&e3,&e4);
	if(e1==e2 && e3==e4 || e1==e3 && e2==e4 ||e1==e4 && e2==e3 ){
		printf("yes\n");
	}
	else
	printf("no\n");
	return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define ll long long int    
#define mod 1000000007
void solve()
{
    ll n;
    cin>>n;
    ll a[n];
    ll x=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        x^=a[i];
    }

    for(int i=0;i<n;i++)
    {
        cout<<(x^a[i])<<" ";
    }
}
int main()
{
    solve();
}

Measured memory_bytes: 5148
#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include<cstdio>
using namespace std;
int main()
{
  string sa,sb;
  int n;
  cin>>n;
  cin>>sa;
  cin>>sb;
  string s;
  for(int i=0,j=0;i<2*n;i=i+2,j++)
  {
    s[i]=sa[j];
    s[i+1]=sb[j];
    
  }
  for(int i=0;i<2*n;i++)
  cout<<s[i];
}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    long N = lread();
    auto S = sread();
    long l;
    long level;
    foreach (c; S)
    {
        if (c == '(')
            level++;
        if (c == ')')
        {
            if (level)
            {
                level--;
            }
            else
            {
                l++;
            }
        }
    }
    long r = level;
    writeln(repeat('(').take(l).array, S, repeat(')').take(r).array);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	cin >> n;
	int t[n+1], x[n+1], y[n+1];
	t[0] = x[0] = y[0] = 0;

	FOR(i, 1, n+1) cin >> t[i] >> x[i] >> y[i];

	REP(i, n){
		int dt = t[i+1] - t[i];
		int dxy = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);

//		cout << "dt = " << dt << " " << "dxy = " << dxy << endl;

		if (dt < dxy){
			cout << "No" << endl;
			return 0;
		}
		if (dxy % 2 != dt % 2){
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
 
using namespace std;
 
int a,b,c,d;
 
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin>>a>>b;
  d=1;c=a;
  if(b==1) 
  {
    cout<<0; return 0;
  }
  while (c<b)
  {
    c=c-1+a;
    d++;
  }
  cout<<d;
  return 0;
}

Measured memory_bytes: 256
// goto campaign
#include<iostream>
#include<string>
using namespace std;

int main(){
        int N,AC = 0, WA = 0, TLE = 0, RE = 0;
        string tmp;
        cin >> N;

        LOOP:
        if(N == 0) goto FINE;

        cin >> tmp;
        if(tmp == "AC") AC++;
        else if(tmp == "WA") WA++;
        else if(tmp == "TLE") TLE++;
        else if(tmp == "RE") RE++;

        N--;
        goto LOOP;

        FINE:
        cout << "AC x " << AC << endl
                << "WA x " << WA << endl
                << "TLE x " << TLE << endl
                << "RE x " << RE << endl;

        return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
const int N=1e6;
ll v[N+10];
int main()
{
     ll n;

     cin>>n;

     ll ara[n+1];

     for(ll i=0;i<n;i++)
     {
         cin>>ara[i];
     }
     sort(ara,ara+n);

     ll cnt=0;

     for(ll i=0;i<n;i++)
     {
         if(i>0&&ara[i-1]==ara[i])
         {
             v[ara[i]]++;
             continue;
         }

         for(ll j=ara[i];j<=N;j+=ara[i])
         {
             v[j]++;
         }
     }



     for(ll i=0;i<n;i++)
     {
         if(v[ara[i]]==1)cnt++;
     }

     cout<<cnt<<endl;

}



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

int n;
long long wt;
int v[100];
long long w[100];
long long dp[101][10001];
const long long INF = 1000000001;

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

	for (int i = 0; i < n; i++)
		cin >> v[i] >> w[i];

	dp[0][0] = 0;
	for (int j = 1; j < 10001; j++)
		dp[0][j] = INF;

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 10001; j++) {
			if (j < v[i - 1])
				dp[i][j] = dp[i - 1][j];
			else
				dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
		}
	}

	int vm = 0;

	for (int j = 1; j < 10001; j++) {
		if (dp[n][j] <= wt)
			vm = j;
	}

	cout << vm << endl;

	return 0;
}


Measured memory_bytes: 11012
#include <iostream>
#include <sstream>
#include <cmath>
#include <string>
#include <vector>
#include <functional>
#include <iomanip>
using namespace std;

int main(void)
{
    int T, D, ta, tb, da, db, i, x, y;
    cin >> T >> D >> ta >> tb >> da >> db;

    x = 1;
    y = 0;
    double min = 1000;

    while (1)
    {
        y = 0;
        if (da * x + db * y > D)
            break;

        while (1)
        {
            if (da * x + db * y > D)
                break;

            if (abs(min) > abs((double)((T - ta) * da * x + (T - tb) * db * y) / (double)(da * x + db * y)))
                min = abs((double)((T - ta) * da * x + (T - tb) * db * y) / (double)(da * x + db * y));
            y++;
        }

        x++;
    }

    if (abs(min) > abs(T - tb))
        min = abs(T - tb);

    cout << fixed << setprecision(15) << min << endl;

    return 0;
}


Measured memory_bytes: 3296
#include <iostream>
using namespace std;
int main() {
	int A,B;
	cin>>A>>B;
  if(A==B){
    cout<<"Draw";
  }
	else if(A==1){
		cout<<"Alice";
	}
	else if(B==1){
	cout<<"Bob"	;
	}
	else if(A>B){
		cout<<"Alice";
	}
	else{
		cout<<"Bob";
	}
		
	
  
return 0;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())

#頂点の色
path = [0 for _ in range(N-1)]
#木グラフ
tree = [[] for _ in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    tree[a-1].append((b-1, i))
    tree[b-1].append((a-1, i))
# print(tree)

que = deque([])
que.append((0, 0))

while que:
    v, pc = que.popleft()
    c = 1
    for nv, i in tree[v]:
        # print(f"nv{nv}, i{i}")
        if path[i] == 0:
            c = c+1 if c == pc else c
            path[i] = c
            que.append((nv, c))
            c += 1
    # print("path", path)
    # print("que", que)
print(max(path))
print(*path, sep="\n")

Measured memory_bytes: 70544
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  bool gudge = true;
  cin >> A >> B >> C >> D;
  
  while(gudge){
  C = C - B;
  A = A - D;
    
    if(C <= 0){
    gudge = false;
    cout << "Yes" << endl;
    }
    else if(A <= 0){
    gudge = false;
    cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 3588
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
#define MAXN 110
#define LL long long
int a[MAXN*2],l=MAXN,r=MAXN,ls=0;
void dfs(LL N)
{
	if(N==1)
	{
		a[l]=++ls;
		return;
	}
	if(N%2)
	{
		dfs(N/2);
		a[++r]=++ls;
	}
	else
	{
		dfs(N-1);
		a[--l]=++ls;
	}
}
LL n;
int main()
{
	scanf("%lld",&n);
	dfs(n);
	printf("%d\n",ls*2);
	for(int i=l;i<=r;i++)
		printf("%d ",a[i]);
	for(int i=1;i<=ls;i++)
		printf("%d ",i);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define for0(i,b) for(int i=0 ; i< b ;i++)
#define for1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007

using namespace std;




int main()
{
 int n, m  ;
 cin >> n >> m ;
 cout << (n*(n-1) + m*(m-1)) / 2 ;



  return 0 ;
}


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

#define FOR(i,start,end) for(int i=start; i<(int)(end); i++)
#define REP(i,n) FOR(i,0,n)
#define SIZE_OF_ARRAY(array)  (sizeof(array)/sizeof((array)[0]))

template<class T> void print(const T& value) { cout << value << "\n"; }

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);

    int x;
    scanf("%d", &x);

    int hour;
    int minute;
    int second;

    hour = x / 3600;
    minute = x % 3600 / 60;
    second = x % 3600 % 60;

    printf("%d:%d:%d\n", hour, minute, second);

    return 0;
}



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

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	String [] resist = new String[n];
    	for(int i=0;i<n;i++) {
    		resist[i] = sc.next();
    	}
    	int m = sc.nextInt();
    	String [] id = new String[m];	
    	for(int i=0;i<m;i++) {
    		id[i] = sc.next();
    	}
    	Arrays.sort(resist);
    	String [] key = {"Opened","Closed"};
    	int j = 0;
    	for(int i=0;i<m;i++) {
    		int a = Arrays.binarySearch(resist, id[i]);
    		if(a>=0) {
    			System.out.println(key[j%2]+" by "+id[i]);
    			j++;
    		}else {
    			System.out.println("Unknown "+id[i]);
    		}
    	}
    }
}



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

string S;

int main() {
    cin >> S;

    ll nums[S.length()+1];
    memset(nums, 0, sizeof(nums));

    ll cnt = 0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] == '<') {
            cnt++;
        }
        else {
            cnt = 0;
        }
        nums[i+1] = cnt;
    }

    cnt = 0;
    for (int i = S.length(); i >= 1; i--) {
        if (S[i-1] == '>') {
            cnt++;
        }
        else {
            cnt = 0;
        }
        nums[i-1] = max(nums[i-1], cnt);
    }

    ll ans = 0;
    for (int i = 0; i <= S.length(); i++) {
        ans += nums[i];
    }

    cout << ans << endl;    

    return 0;
}


Measured memory_bytes: 4740
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int X, Y, x, y;

int main(void) {

	cin >> X >> Y;

	for (int x = 0; x <= 100; x++) {
		for (int y = 0; y <= 100; y++) {
			if (x + y == X && 2 * x + 4 * y == Y) { cout << "Yes" << endl; return 0; }
		}
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3124
import java.util.*;

import static java.lang.System.*;

class Main {
    public static Scanner sc = new Scanner(in);
    public static Random rand=new Random();

    static class P{
    	int x;
    	int y;
    	public P(int x,int y){
    		this.x=x;this.y=y;
    	}

    	@Override
    	public boolean equals(Object obj) {
    		if(!(obj instanceof P))return false;
    		P p=(P)obj;
    		return p.x==x && p.y==y;
    	}
    	@Override
    	public String toString() {
    		return "("+x+","+y+")";
    	}
    }

    int[][] dr=new int[][]{{-1,0},{0,-1},{1,0},{0,1}};
    public void run() {
        Test:while(true){

        	int mx=0,my=0,Mx=0,My=0;
        	int N=sc.nextInt();
        	if(N==0)return;
        	P[] data=new P[N];
        	data[0]=new P(0,0);
        	int ind=1;
            for(int i=0;i<N-1;i++){
            	int n=sc.nextInt(),d=sc.nextInt();
            	data[ind]=new P(data[n].x+dr[d][0],data[n].y+dr[d][1]);
            	mx=Math.min(data[ind].x,mx);
            	Mx=Math.max(data[ind].x,Mx);

            	my=Math.min(data[ind].y,my);
            	My=Math.max(data[ind].y,My);
            	ind++;
            }

            ln((Mx-mx+1)+" "+(My-my+1));
        }
    }
    public static void main(String[] args) {
        new Main().run();
    }

    public int[] nextIntArray(int n){
        int[] res=new int[n];
        for(int i=0;i<n;i++){
            res[i]=sc.nextInt();
        }
        return res;
    }
    public static void pr(Object o) {
        out.print(o);
    }
    public static void ln(Object o) {
        out.println(o);
    }
    public static void ln() {
        out.println();
    }
}

Measured memory_bytes: 34800
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>

using namespace std;

double dot(double x1,double y1,double x2,double y2){return x1*y2 - x2*y1;}

int main(){
	int t;
	cin>>t;
	while(t--){
		double x[4],y[4];
		for (int i = 0; i < 4; i++)
		{
			cin>>x[i]>>y[i];
		}

		double ans = dot(x[1] - x[0],y[1]-y[0],x[3]-x[2],y[3]-y[2]);
		if(-1e-8 <= ans && ans <= 1e-8) puts("YES");
		else puts("NO");
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define LL long long
using namespace std;

LL k, a[200005];

int main () {
    //clock_t start = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n >> k;
    for (int i=1;i<=n;i++) cin >> a[i];
    a[0]=0;
    for (int i=1;i<=n;i++) {
        a[i]+=a[i-1];
    }
    for (int i=1;i<=n;i++) {
        a[i]-=i;
        a[i]%=k;
    }
    LL ans=0;
    map<LL,int> c;
    c[a[0]]++;
    if (k > n) k = n+1;
    for (int i=1;i<k;i++) {
        ans += c[a[i]];
        c[a[i]]++;
    }
    for (int i=k;i<=n;i++) {
        c[a[i-k]]--;
        ans += c[a[i]];
        c[a[i]]++;
    }
    cout << ans << endl;
    //cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 14336
#include <stdio.h>
#include <stdlib.h>
int compare(const void *a,const void *b){
    if(*(int *)a>*(int *)b)return 1;
    return -1;
}
int main()
{   int n,k;
    scanf("%d%d",&n,&k);
    int a[n],copy[n],cn=n;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]==k){
            printf("POSSIBLE");
            return 0;
        }
        copy[i]=a[i];
    }
    qsort(a,n,sizeof(int),compare);
    if(a[n-1]<k){
    printf("IMPOSSIBLE");
    return 0;
    }
    while(n>1){
    for(int i=1;i<n;i++){
        a[i]%=a[0];
    }
    qsort(a,n,sizeof(int),compare);
    int i=0;
    while(a[i]==0)i++;
    if(i)for(int j=0;j<n-i;j++){
        a[j]=a[j+i];
    }
    n-=i;
    }
    for(int i=0;i<cn;i++){
        if(copy[i]>k&&(copy[i]%k)%a[0]==0){
            printf("POSSIBLE");
            return 0;
        }
    }
    printf("IMPOSSIBLE");
    return 0;
}


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

int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double a_r = 360.0/12.0*h + 30.0/60.0*m;
    double b_r = 360.0/60.0*m;
    double a_b_abs = abs(a_r - b_r);
    double rad = (360-a_b_abs) < a_b_abs
        ? (360-a_b_abs)* PI/180.0
        : a_b_abs * PI / 180.0;
    double z = sqrt( pow(a, 2) + pow(b, 2) -2*a*b*cos(rad));
    cout << fixed << setprecision(20) <<  z;
    return 0;
}


Measured memory_bytes: 4216
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;

void main(){
  auto ip = readln.split.to!(int[]);
  if(ip[0] + ip[1] >= ip[2]){
    writeln("Yes");
  } else {
    writeln("No");
  }
}

Measured memory_bytes: 256
// The moment you think of giving up you have already lost the battle
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define M   1000000007
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }

    }
}
const ll N=1e6+5;
ll dp[N]={0},cnt[N]={0},res[N]={0};
int main()
{
   ll n,i;
   cin>>n;
   ll A[n];

   for(i=0;i<n;i++)
   {
       cin>>A[i];
       res[A[i]]++;

   }
   ll g=A[0];
   for(i=1;i<n;i++)
    g=__gcd(g,A[i]);

    ll j;

   for(i=1;i<N;i++)
   {
       for(j=i;j<N;j+=i)
       {
           cnt[i]+=res[j];
       }
   }
   for(i=1;i<N;i++)
   {
       ll d=cnt[i];
       ll r=d*(d-1);
       r/=2;
       dp[i]=r;
   }
   for(i=N-1;i>=1;i--)
   {
       for(j=i*2;j<N;j+=i)
       {
           dp[i]-=dp[j];
       }
   }
   ll f=n*(n-1);
   f/=2;
   if(dp[1]==f)
    cout<<"pairwise coprime";
   else
   {
       if(g==1)
        cout<<"setwise coprime";
       else
        cout<<"not coprime";
   }

}


Measured memory_bytes: 34836
#include <stdio.h>

int main(void)
{
  int r,g,b;
  scanf("%d",&r);
  scanf("%d",&g);
  scanf("%d",&b);
  
  if((g*10 + b) % 4 == 0)
    printf("YES");
  else
    printf("NO");
  
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		int C = Integer.parseInt(sc.next());
		sc.close();

		int rem = C - (A - B);
		if(rem > 0) {
			System.out.println(rem);
		}else {
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int mo=998244353;
const int N=405;
int n,a[N],C[N][N],P[N];
int lson[N*2],rson[N*2];
int val[N*2],len[N*2],nd;
int f[N*2][N],g[N*2][N];
int tf[N],tg[N];
void init(){
	For(i,0,N-1) C[i][0]=1;
	For(i,1,N-1) For(j,1,i) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mo;
	For(i,(P[0]=1),N-1) P[i]=2ll*P[i-1]%mo;
}
int build_tr(int l,int r){
	if (l>r) return 0;
	int p=l,k=++nd;
	For(i,l,r) if (a[i]<a[p]) p=i;
	val[k]=a[p]; len[k]=r-l+1;
	lson[k]=build_tr(l,p-1);
	rson[k]=build_tr(p+1,r);
	return k;
}
void get_ans(int x,int lad){
	if (!x) return;
	int sz=len[x];
	int ls=lson[x],n=len[ls];
	int rs=rson[x],m=len[rs];
	get_ans(ls,val[x]);
	get_ans(rs,val[x]);
	For(i,0,n) For(j,0,m){
		f[x][i+j]=(f[x][i+j]+1ll*f[ls][i]*f[rs][j])%mo;
		f[x][i+j+1]=(f[x][i+j+1]+1ll*f[ls][i]*f[rs][j])%mo;
		g[x][i+j+1]=(g[x][i+j+1]+1ll*g[ls][i]*g[rs][j])%mo;
	}
	For(T,1,val[x]-lad){
		memset(tf,0,sizeof(tf));
		memset(tg,0,sizeof(tg));
		For(j,0,sz){
			tf[j]=(tf[j]+g[x][j])%mo;
			tg[j]=(tg[j]+g[x][j])%mo;
			For(k,0,sz-j){
				int dif=1ll*P[j]*C[j+k][k]%mo;
				if (!k) dif=(dif+mo-1)%mo;
				tf[j]=(tf[j]+1ll*dif*f[x][j+k])%mo;
				tg[j]=(tg[j]+1ll*dif*g[x][j+k])%mo; 
			}
		}
		memcpy(f[x],tf,sizeof(tf));
		memcpy(g[x],tg,sizeof(tg));
	}
}
int main(){
	init();
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]);
	int rt=build_tr(1,n);
	f[0][0]=g[0][0]=1; 
	get_ans(rt,0);
	printf("%d\n",f[rt][0]);
}


Measured memory_bytes: 2176
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] a = new int[M];
    int[] b = new int[M];

    HashMap<Integer, Set<Integer>> hashMap = new HashMap<>();

    for (int i = 0; i < M; i++) {
      int a_ = sc.nextInt();
      int b_ = sc.nextInt();
      Set<Integer> set_;
      if (hashMap.containsKey(a_)){
        set_ = hashMap.get(a_);
      } else {
        set_ = new HashSet<Integer>();
      }
      set_.add(b_);
      hashMap.put(a_, set_);
    }

    sc.close();
    
    String result = "IMPOSSIBLE";

    Set<Integer> set = hashMap.get(1);

    for(Integer value : set) {
      if (hashMap.containsKey(value)){
        Set<Integer> set_ = hashMap.get(value);
        for(Integer value_ : set_) {
          if (value_ == N) {
            result = "POSSIBLE";
            break;
          }
        }
      }
      if (result.equals("POSSIBLE")) {
        break;
      }
    }

    System.out.println(result);

  }

}


Measured memory_bytes: 154128
// A

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

int main(){
  ll N,A,B;
  cin>>N>>A>>B;
  if ((A - B)%2==0){
    cout << (max(A,B) - min(A,B)) / 2 << endl;
  }else{
    ll tmp1,tmp2;
    tmp1 = min(A,B) + (max(A,B) - min(A,B) - 1)/2;
    A = N - A + 1;
    B = N - B + 1;
    tmp2 = min(A,B) + (max(A,B) - min(A,B) - 1)/2;
    cout << min(tmp1,tmp2) << endl;
  }
  return 0;
}


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

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

const long long INF = 1LL << 60;
long long dp[100100];

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

    int flag = 1;
    int cnt = 0;
    int i = 0;
    while(flag) {
        flag = 0;
        for(int j = N-1; j >= i+1; j--) {
            if(A[j] < A[j-1]) {
                swap(A[j], A[j-1]);
                cnt++;
            }
            flag = 1;  
        }
        i++;
    }

    for(int i = 0; i < N; i++) {
        if(i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mood) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mood;
		}
		x = x * x % mood;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n;
vector<P> ans;
int cnt;

signed main() {
	cin >> n;
	for (int i = 1; i <= n / 2 * 2; i++) {
		for (int j = i + 1; j <= n / 2 * 2; j++) {
			if (i + j != n / 2 * 2 + 1) {
				ans.push_back({ i,j });
				cnt++;
			}
		}
	}
	if (n % 2) {
		for (int i = 1; i < n; i++) {
			ans.push_back({ i,n });
			cnt++;
		}
	}
	cout << cnt << endl;
	for (int i = 0; i < (int)ans.size(); i++) {
		cout << ans[i].first << " " << ans[i].second << endl;
	}
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
from heapq import heappush, heappop

N, M, S = map(int, input().split())
STATE = 50 * N + 1
vec = [[] for _ in range(STATE * N)]
for _ in range(M) :
  U, V, A, B = map(int, input().split())
  U -= 1
  V -= 1
  for silver in range(A, STATE) :
    vec[STATE * U + silver].append((STATE * V + silver - A, B))
    vec[STATE * V + silver].append((STATE * U + silver - A, B))
  
for i in range(N) :
  C, D = map(int, input().split())
  for silver in range(STATE - C) :
    vec[STATE * i + silver].append((STATE * i + silver + C, D))

dist = [float('inf')] * (STATE * N)

S = min(S, STATE - 1)
dist[S] = 0
q = [(0, S)]
while q :
  cc, cur = heappop(q)
  for nex, nc in vec[cur] :
    if dist[nex] <= cc + nc :
      continue
    dist[nex] = cc + nc
    heappush(q, (cc + nc, nex))

for i in range(1, N) :
  print(min(dist[STATE * i:STATE * (i + 1)]))

Measured memory_bytes: 118232
#include <stdio.h>

int main(void){
  int i,N,ans=0;
  double D;

  scanf("%d %lf",&N,&D);
  double X[N],Y[N];
  
  for(i=0;i<N;i++){
    scanf("%lf %lf",&X[i],&Y[i]);
  }

  for(i=0;i<N;i++){
	if(D*D >= X[i]*X[i]+Y[i]*Y[i]){
      ans++;
    }
  }

  printf("%d",ans);
  
  return 0;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int n, m, Q;
  cin >> n >> m >> Q;
  vector<int> l(m + 1), r(m + 1);
  vector<vector<LL>> lr(n + 1, vector<LL>(n + 1, 0));
  for (int i = 1; i <= m; i ++) {
    cin >> l[i] >> r[i];
    lr[l[i]][r[i]] ++;
  }

  vector<vector<LL>> sum(n + 1, vector<LL>(n + 1, 0));
  for (int i = 1; i <= n; i ++) {
    for (int j = 1; j <= n; j ++) {
      sum[i][j] = sum[i][j - 1] + lr[i][j];
    }
  }

  rep(i, Q) {
    int p, q; cin >> p >> q;
    int ans = 0;
    for (int j = p; j <= q; j ++) ans += sum[j][q] - sum[j][p - 1];
    cout << ans << endl;
  }
}

Measured memory_bytes: 6400
s = str(input())
n = len(s)-1

item = [i for i in range(n)]

res = 0
for i in range(2**n):
    bag = []
    for j in range(n):
        if (i>>j) & 1:
            bag.append(item[j])

    sp = ''
    for i, keta in enumerate(s):
        sp += keta
        if i in bag: sp += '+'
    
    sl = sp.split('+')
    sl = list(map(int, sl) )
    res += sum(sl)
print(res)

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

int main(void) {
    char sa[101], sb[101], sc[101];
    scanf("%s", sa);
    scanf("%s", sb);
    scanf("%s", sc);
    int a = (int)strlen(sa);
    int b = (int)strlen(sb);
    int c = (int)strlen(sc);
    char temp = 'a';
    while(1) {
        if(temp == 'a') {
            a--;
            if(a == -1) break;
            temp = sa[0];
            for(int i = 0; i < a+1; i++) {
                sa[i] = sa[i+1];
            }
        } else if(temp == 'b') {
            b--;
            if(b == -1) break;
            temp = sb[0];
            for(int i = 0; i < b+1; i++) {
                sb[i] = sb[i+1];
            }
        } else if(temp == 'c') {
            c--;
            if(c == -1) break;
            temp = sc[0];
            for(int i = 0; i < c+1; i++) {
                sc[i] = sc[i+1];
            }
        }
    }
    if(a == -1)  {
        printf("A\n");
        return 0;
    } else if(b == -1) {
        printf("B\n");
        return 0;
    } else if(c == -1) {
        printf("C\n");
        return 0;
    }
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int INF=2000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

typedef pair<P,vector<int>> P2;

vector<int> emp;

int main(){
	while(1){
		int n,m;
		scanf("%d%d",&n,&m); if(n == 0 && m == 0)break;
		
		vector<P2> DP[152];
		rep1(i,n){
			int k;
			scanf("%d",&k);
			rep(j,k){
				int x,y;
				scanf("%d%d",&x,&y);
				DP[i].pb(P2(P(x,y),emp));
			}
		}
		
		rep1(i,n){
			rep(j,DP[i].size()){
				rep(k,m+1){
					int dp = INF;
					if(i == 1){
						dp = 0;
					}
					else if(i == 2 && k > 0){
						dp = 0;
					}
					else {
						rep(l,DP[i-1].size()){
							dp = min ( dp , DP[i-1][l].sc[k] + (DP[i][j].fr.sc+DP[i-1][l].fr.sc) * abs(DP[i][j].fr.fr-DP[i-1][l].fr.fr) );
						}
						if(k > 0){
							rep(l,DP[i-2].size()){
								dp = min ( dp , DP[i-2][l].sc[k-1] + (DP[i][j].fr.sc+DP[i-2][l].fr.sc) * abs(DP[i][j].fr.fr-DP[i-2][l].fr.fr) );
							}
						}
					}
					DP[i][j].sc.pb(dp);
				}
			}
		}
		
		int ret = INF;
		
		rep(i,DP[n].size()){
			rep(j,m+1){
				ret = min ( ret , DP[n][i].sc[j] );
			}
		}
		if(n > 1){
			rep(i,DP[n-1].size()){
				rep(j,m){
					ret = min ( ret , DP[n-1][i].sc[j] );
				}
			}
		}
		
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 2028
#include <iostream> 
#include <vector> 
#include <climits> 
using namespace std; 
typedef long long ll; 
struct force{ ll val; ll cost; } ;
ll go(ll h,vector<force> &a,vector<ll> &dp){
	if (h <= 0){ 
		return 0; 
	} 
	ll &memo = dp[h];
	if (memo != -1){
		return memo;
	}
	ll ans = INT_MAX; 
	for(int i = 0; i < a.size(); i++)
	{ 
		ans = min(ans,go(h - a[i].val,a,dp) + a[i].cost); 
		
	} 
	return memo = ans; 
	
} int main() { 
	ll h,n; 
	cin >> h >> n; 
	vector<force> a(n); 
	vector<ll> dp(h + 1,-1);
	for(int i = 0; i < n; i++)
	{ 
		cin >> a[i].val >> a[i].cost; 
	} 
	cout << go(h,a,dp) << endl; 
	return 0; 
	
}

Measured memory_bytes: 1152
a, b, k = [int(x) for x in input().split()]
if a<=k:
    k -= a
    a = 0
    if b<=k:
        k -= b
        b = 0
    elif b>k:
        b -= k
        k = 0
else:
    a -= k
    k = 0
print(str(a)+" "+str(b))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n;
double p[111111],dp[111111];
deque<int> q,qq;
struct node
{
	double s,p;
	node()
	{
		p=1.00;
		s=0.00;
	}
	node operator + (const node &u) const
	{
		node res;
		res.s=s+p*u.s;
		res.p=p*u.p;
		return res;
	}
}f[111111][22],cx,cy,nx,ny;
node cost(int l,int r)
{
	node res;
	for (int i=18;i>=0;i--)
	{
		if (r-(1<<i)+1>=l)
		{
			res=res+f[r][i];
			r-=(1<<i);
		}
	}
	return res;
}
int get_ver(int x,int y)//get the first point that dp[x]+cost(x+1,i)>=dp[y]+cost(y+1,i),x<y
{
	cx=cost(x+1,y);cy=node();
	int ans=y;
	for (int i=18;i>=0;i--)
	{
		if (ans+(1<<i)<=n)
		{
			nx=f[ans+(1<<i)][i]+cx;ny=f[ans+(1<<i)][i]+cy;
			if (dp[x]+nx.s<dp[y]+ny.s)
			{
				ans+=(1<<i);
				cx=nx;cy=ny;
			}
		}
	}
	return ans+1;
}
int main()
{
	while(scanf("%d",&n)==1)
	{
		if (!n) break;
		for (int i=1;i<=n;i++) scanf("%lf",&p[i]);
		for (int i=1;i<=n;i++) f[i][0].s=f[i][0].p=1.00/p[i];
		for (int i=1;i<=18;i++)
		{
			for (int j=(1<<i);j<=n;j++)
			{
				f[j][i]=f[j][i-1]+f[j-(1<<(i-1))][i-1];
			}
		}
		q.clear();qq.clear();
		q.push_back(0);qq.push_back(0);
		dp[0]=0.00;
		for (int i=1;i<=n;i++)
		{
			while(q.size()>1 && qq[1]<=i) 
			{
				q.pop_front();
				qq.pop_front();
			}
			dp[i]=dp[q.front()]+cost(q.front()+1,i).s+1.00;
			while(q.size()>1 && get_ver(q.back(),i)<=qq.back())
			{
				q.pop_back();qq.pop_back();
			}
			qq.push_back(get_ver(q.back(),i)); 
			q.push_back(i); 
		} 
		printf("%.10lf\n",dp[n]-1.00);
	}
	return 0;
}


Measured memory_bytes: 42916
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) break;
        int w[n];
        for (auto &wi:w) cin >> wi;
        bool erase[n][n];
        fill(erase[0], erase[n], false);
        for (int d=1; d<n; d++) {
            for (int i=0; i+d<n; i++) {
                if ((d == 1 || erase[i+1][i+d-1]) && abs(w[i] - w[i+d]) <= 1)
                    erase[i][i+d] = true;
                for (int j=i+1; j+1<i+d; j++) {
                    if (erase[i][j] && erase[j+1][i+d]) erase[i][i+d] = true;
                }
            }
        }
        int dp[n+1];
        fill(dp, dp+n+1, 0);
        for (int i=0; i<n; i++) {
            for (int j=i+1; j<n; j++) {
                if (erase[i][j]) {
                    dp[j+1] = max(dp[j+1], dp[i] + j - i + 1);
                }
            }
            dp[i+1] = max(dp[i+1], dp[i]);
        }
        cout << dp[n] << '\n';
    }
    return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}


int main(){
  ll n,x,y;
  cin >> n >> x >> y;

  vector<ll> ans(n,0);

  FOR(i,1,n+1){
    FOR(j,i+1,n+1){
      ll d = j-i;
      d = min(d,abs(i-y)+abs(j-x)+1);
      d = min(d,abs(j-y)+abs(i-x)+1);
      ans[d]++;
    }
  }

  for(int i=1;i<n;i++){
    cout << ans[i] << endl;
  }

}

Measured memory_bytes: 256
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
# import numpy as np
from math import gcd

sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10 ** -7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)


K = inp()

dic = {} # key: (i, j, k), el: gcd(i, j, k)
ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        # tmp = gcd(i, j)
        for k in range(j, K + 1):
            # a = gcd(tmp, k)
            a = gcd(gcd(i, j), k)
            if i == j == k:
                ans += a
            elif i == j or j == k:
                ans += a * 3
            else:
                ans += a * 3 * 2
print(ans)


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

#define int long long
const int mod = 2019;

signed main()
{
    int l,r;
    cin >> l >> r;
    
    if(r - l > 2019)
    {
        cout << 0;
        return 0;
    }
    else
    {
        l%= mod;
        r%= mod;
        if(l > r) swap(l,r);
        int mini = 1e18;
        for(int i = l; i < r; ++i)
        {
            for(int j = i + 1; j <= r; ++j)
            {
                mini = min(mini,(i*j)%mod);
            }
        }
        cout << mini;
    }
    
    
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXM 100
char s[MAXM+10]; 
bool a[MAXM+10],b[MAXM+10];   
int main()
{
    int n,m,ans;  
    int i,j;
    scanf("%d",&n); 
    scanf("%s",s);
    for(i=0;i<n;i++)
	{
        a[s[i]-'a']=1; 
        memset(b,false,sizeof(b));  
        
        for(j=i+1;j<n;j++)
		{   
            b[s[j]-'a']=1;  
        }
        m=0; 
        for(j=0;j<26;j++)
		{
            if(a[j] && b[j])
			{    
                m++; 
            } 
        } 
        ans=max(ans,m); 
    }
    printf("%d",ans); 
    return 0; 
} 

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

int main()
{
	int t[2], a[2];
	cin >> t[0] >> t[1] >> a[0] >> a[1];
	while (1)
	{
		a[0] -= t[1];
		if (a[0] <= 0)
		{
			break;
		}
		t[0] -= a[1];
		if (t[0] <= 0)
		{
			break;
		}
	}
	if (a[0] <= 0)
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}
	return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;

void add(int& a, int b){
	a += b;
	if(a >= mod){
		a -= mod;
	}
}

void sub(int& a, int b){
	a -= b;
	if(a < 0){
		a += mod;
	}
}

int main(void){
	int n, m;
	cin >> n >> m;
	vector<int> s(n + 1), t(m + 1);
	for(int i = 1 ; i <= n ; i++){
		cin >> s[i];
	}
	for(int j = 1 ; j <= m ; j++){
		cin >> t[j];
	}
	vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0)); 
	vector<vector<int>> sum(n + 1, vector<int>(m + 1, 0));
	for(int i = 1 ; i <= n ; i++){
		for(int j = 1 ; j <= m ; j++){
			add(sum[i][j], sum[i - 1][j]);
			add(sum[i][j], sum[i][j - 1]);
			sub(sum[i][j], sum[i - 1][j - 1]);
			if(s[i] != t[j]) continue;
			add(dp[i][j], sum[i - 1][j - 1] + 1);
			add(sum[i][j], dp[i][j]);
		}
	}
	int ans = 1;
	for(int i = 1 ; i <= n ; i++){
		for(int j = 1 ; j <= m ; j++){
			add(ans, dp[i][j]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 32000
def solve(n,x):
    count = 0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            k = x - i - j
            if j < k and k <= n:
                count += 1
    return count

while True:
    n,x = map(int,input().split())
    if n == x == 0:
        break;
    print(solve(n,x))

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

using namespace std ;
typedef long long ll;
typedef string str;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll ;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef vector<pii> vpii ;
typedef vector<pll> vpll ;

#define REP(i, n) for (ll (i) = 0; (i) < (ll)(n); i++) 
#define FOR(i, a, b) for(ll (i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define CHI 1000000000000000003
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define NP next_permutation
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}
//-----------------------------------------





ll pow(ll x,ll y,ll m){
    ll res = 1 ;
    if(y>0){
        res = pow(x,y/2,m) ;
        if(y%2==0){
            res = (res*res)%m ;
        }
        else{
            res = (((res*res)%m)*x)%m ;
        }
    }
    return res ;
}














//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, a, b ;
  cin >> n >> a >> b ;
  ll ans = 0 ;
  ans = pow(2,n,MOD) ;
  ans += (MOD - 1) ;
  ans %= MOD ;
  
  ll nCa, nCb ;
  nCa = nCb = 1 ;
  REP(i,a){
    nCa *= (n-i) ;
    nCa %= MOD ;
  }
  ll tmp = 1 ;
  REP(i,a){
    tmp *= (i+1) ;
    tmp %= MOD ;
  }
  tmp = pow(tmp,MOD-2,MOD) ;
  nCa *= tmp ;
  nCa %= MOD ;
  
  REP(i,b){
    nCb *= (n-i) ;
    nCb %= MOD ;
  }
  ll tmpb = 1 ;
  REP(i,b){
    tmpb *= (i+1) ;
    tmpb %= MOD ;
  }
  
  tmpb = pow(tmpb,MOD-2,MOD) ;
  nCb *= tmpb ;
  nCb %= MOD ;
  
  cout << (ans - nCa - nCb+MOD+MOD)%MOD <<endl ;
    
    
  
  
  
  return 0 ;
}

Measured memory_bytes: 256